Solved

unescape

Posted on 2011-10-01
5
339 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 500 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will learn how to count occurrences of each item in an array.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

756 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