Solved

unescape

Posted on 2011-10-01
5
330 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
  • 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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now