?
Solved

unescape

Posted on 2011-10-01
5
Medium Priority
?
344 Views
Last Modified: 2012-05-12
Hi, in Flash I am using google translate to take some text, translate it and then put it back in a text box in a chosen language. I have a list of languages to choose etc and it works fine except i end up with things like u0026quot (in the trace) being returned and then using unescape() seems to help but results in uuot still being displayed. The key part of the code is at the bottom of the following.

Any suggestions welcome.
Tom
on (release) {

	var lorem_lv:LoadVars = new LoadVars();
	txtLang.text = "Current language code is: " + lstLang.getSelectedItem().data;
	strLang = lstLang.getSelectedItem().data;
	btnReset._visible = true
	
	if (strLang == null) {
		strLang = "en";
		txtLang.text = lstLang.getSelectedItem().data;
	}

	lorem_lv.onData = function(src:String):Void  {
		clip(src);
		trace(src);
	}

	strSource = escape(txtContent.text);
	//strSource = txtContent.text;
	lorem_lv.load("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + strSource + "&langpair=en%7C" + strLang);

	function clip(str:String):Void {
		find_me = "translatedText";
		trace("Found "+str.indexOf(find_me));
		str = str.substr(str.indexOf(find_me)+17, str.length);
		str = str.substr(0, str.indexOf("},")-1);
		txtContent.htmlText = unescape(str);
	}

}

Open in new window

0
Comment
Question by:tomdenton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:dgofman
ID: 36897057
Can you use AS3?
0
 

Author Comment

by:tomdenton
ID: 36897109
If I have to yes, but is it possible in 1 or 2 do you think?
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36897128
Yes it's possible the reason why I like AS3 I will use a JSON class. But it's fine I can use as2 as well.
0
 
LVL 4

Accepted Solution

by:
ute_arbeit earned 2000 total points
ID: 36897250
Hi,

the \u0026 is the unicode character code for the ampersand. You have to replace it like so in your line 27:

str = unescape(str);
find_me = "\\u0026";
pos = str.indexOf(find_me);
while (pos >= 0) {
    str = str.substr (0, pos) + "&" + str.substr(pos + find_me.length, str.length);
    pos = str.indexOf(find_me);
}
txtContent.htmlText = str;

Open in new window


Cheers
0
 

Author Closing Comment

by:tomdenton
ID: 36897787
Great, thanks
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
The viewer will learn how to dynamically set the form action using jQuery.
The goal of the tutorial is to teach the user how to how to record live broadcast.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question