View comments | RSS feed

unescape function

unescape(string:String) : String

Evaluates the parameter x as a string, decodes the string from URL-encoded format (converting all hexadecimal sequences to ASCII characters), and returns the string.

Availability: ActionScript 1.0; Flash Player 5

Parameters

string:String - A string with hexadecimal sequences to escape.

Returns

String - A string decoded from a URL-encoded parameter.

Example

The following example shows the escape-to-unescape conversion process:


var email:String = "user@somedomain.com";
trace(email);
var escapedEmail:String = escape(email);
trace(escapedEmail);
var unescapedEmail:String = unescape(escapedEmail);
trace(unescapedEmail);

The following result is displayed in the Output panel.

user@somedomain.com
user%40somedomain%2Ecom
user@somedomain.com

Version 8

Comments


Mr. Allen Manning said on Feb 22, 2006 at 8:27 AM :
I was debugging an issue, and apparently unescape(null) != null. Can you confirm this and let me know if this is intended behavior?

Thanks,
Al
No screen name said on Feb 7, 2007 at 12:46 PM :
the unescape global function in flash 8 does :

Evaluates the parameter x as a string, decodes the string from URL-encoded format (converting all hexadecimal sequences to ASCII characters), and returns the string.

However when converting the hexadecimal values from %E9 to %FB is doesn't work.

These are those little characters that people that don't understand about XML and coding always want in their text, like Café and Tiburón, even if they break the code.

Can anyone provide guidance on how to escape and unescape these characters?
Crossems said on May 14, 2007 at 9:04 AM :
This is how I am able to get Flash to deal with special characters that the unescape command does not handle.

I setup an array of objects that holds the hex code and the correct character i want to get from that hex code.

I then build a function that will evaluate the entire string ( BEFORE USING THE UNESCAPE FUNCTION ON THAT STRING ) to replace all the hex codes with the characters I want. I then return the cleaned up string, and use the built in unescape function to handle the rest.

Here is the code:

BadLetters = new Array( {HexCode:"2019", Let:"\'" },
{HexCode:"201C", Let:"\"" },
{HexCode:"201D", Let:"\"" },
{HexCode:"%E0", Let:"à"},
{HexCode:"%E1", Let:"á"},
{HexCode:"%E2", Let:"â"},
{HexCode:"%E3", Let:"ã"},
{HexCode:"%E4", Let:"ä"},
{HexCode:"%E5", Let:"å"},
{HexCode:"%E6", Let:"æ"},
{HexCode:"%E7", Let:"ç"},
{HexCode:"%E8", Let:"è"},
{HexCode:"%E9", Let:"é"},
{HexCode:"%EA", Let:"ê" },
{HexCode:"%EB", Let:"ë" },
{HexCode:"%EC", Let:"ì" },
{HexCode:"%ED", Let:"í" },
{HexCode:"%EE", Let:"î"},
{HexCode:"%EF", Let:"ï" },
{HexCode:"%F0", Let:"ð" },
{HexCode:"%F1", Let:"ñ" },
{HexCode:"%F2", Let:"ò" },
{HexCode:"%F3", Let:"ó" },
{HexCode:"%F4", Let:"ô" },
{HexCode:"%F5", Let:"õ" },
{HexCode:"%F6", Let:"ö" },
{HexCode:"%F7", Let:"÷" },
{HexCode:"%F8", Let:"ø" },
{HexCode:"%F9", Let:"ù" },
{HexCode:"%FA", Let:"ú" },
{HexCode:"%FB", Let:"û"},
{HexCode:"%0A", Let:" "})

function CleanText(Crap) {
var TmpStr:String = Crap
//take the Crap text and replace the hexidecimal chracters with the correct character
f=Number(0)
while (f<BadLetters.length) {
if(TmpStr.indexOf(BadLetters[f].HexCode) != -1) {
TmpStr = (TmpStr.slice(0, (TmpStr.indexOf(BadLetters[f].HexCode)) ) )+""+BadLetters[f].Let+""+(TmpStr.slice( (TmpStr.indexOf(BadLetters[f].HexCode)+(BadLetters[f].HexCode.length)), TmpStr.length ) )
} else {
f++
}
}
return(TmpStr)
break
}
juankpro said on Aug 1, 2007 at 9:45 AM :
Even though it doesn't work for ASCII single escape syntax Latin (or other languages) characters. It does work for the UTF double escape syntax for any character. This UTF-8 syntax uses double escapes for characters outside the common english characters.

For example for the letter á it uses the UTF-8 representation %C3%A1 instead of the ASCII %E1 escape code. I think it is better this way to support foreign languages like mine.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001779.html