AS3 encoding conversion function Tags: Functions, encoding
As3.0 adds a public class function similar to the escape, encodeURI, encodeuricomponent, etc. in JavaScript ...
1.decodeURI () function [as3.0 new]
as3.0 syntax: Public function decodeURI (uri:string): String
Syntax: Public function decodeURI (uri:string): String
Returns a non-encoded form of an encoded Uniform Resource Identifier (URI). If the encoding result is passed to encodeURI, the initial string is returned. decodeURI does not encode the following characters: ":", "/", ";" and "?". Please use decodeURIComponent to encode these characters.
Input/Output %23 # %24 $ %26 & %2B + %2C, %2F/ %3A: %3b; %3d = %3f? %40 @
Parameters:
uri:string--A string that represents the encoding URI.
Return: String
Example: Copy content to Clipboard code: package { Import Flash.display.Sprite; public class Decodeuriexample extends Sprite { Public Function Decodeuriexample () { var uri:string = "Http://www.example.com/application.jsp?user=%3Cuser%20name= ' Some%20user '%3e%3c/user%3e"; var decoded:string=decoded (URI); Trace (decoded); Http://www.example.com/application.jsp?user=<user name= ' Some user ' ></user> } } } } 2.decodeURIComponent () function [as3.0 new]
as3.0 syntax: Public function decodeURIComponent (uri:string): String
Returns the non-encoded form of an encoded component of a Uniform Resource Identifier (URI).
Parameters:
uri:string--A value that represents the encoded URI component.
Return: String
Example: Copy content to Clipboard code:??? 3.encodeURI () function [as3.0 new]
as3.0 syntax: Public function encodeURI (uri:string): String
Returns a string encoded as a valid Uniform Resource Identifier (URI). If the encoding result is passed to decodeURI, the initial string is returned. encodeURI does not encode the following characters: ":", "/", ";" and "?". Please use encodeURIComponent to encode these characters.
Non-coding:
0 1 2 3 4 5 6 7 8 9 A b c d e F g h i j k l m n o p q R S t u v w x y Z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ; / ? : @ & = + $, # - _ . ! ~ * ' ( )
Parameters: uri:string--A string that represents the encoding URI
Return: string copy contents to Clipboard code: package { Import Flash.display.Sprite; public class Encodeuriexample extends Sprite { Public Function Encodeuriexample () { var uri:string = "Http://www.example.com/application.jsp?user=<user name= ' some user ' ></user>"; var Encode:string=encodeuri (URI); Trace (encode); Http://www.example.com/application.jsp?user=%3Cuser%20name= ' Some%20user '%3e%3c/user%3e } } } } 4.encodeURIComponent () function [as3.0 new]
as3.0 syntax: Public function encodeURIComponent (uri:string): String
Returns a string of valid components encoded as a Uniform Resource Identifier (URI).
Parameters: uri:string--A string that represents the encoding URI component.
Return: String
Example: Copy content to Clipboard code:??? 5.escape () function
as3.0 syntax: Public function Escape (str:string): String
Returns an encoded String object that can be read on all computers. Converts a parameter to a string and encodes it in a URL-encoded format, in which all non-alphanumeric characters nonalphanumeric replaced by a% hexadecimal sequence. Percent percent (%) when used in a URL-encoded string Used to introduce escape characters, not with modulo operator (%) Equivalent. Parameters: str:string--any string object or text to encode (expressed as a string and encoded in a URL-encoded format)
Return: String
Instance one: Copy the contents to the Clipboard code://The following code generates the result someuser%40somedomain%2ecom: var email:string = "someuser@somedomain.com"; Trace (Escape (email)); Example two: In this example, the at sign (@) is replaced with%40, and the dot symbol (.) is replaced with%2e. If you are trying to pass information to a remote server, and the data contains special characters (such as,& or?), it is useful, as shown in the following code: Copy content to Clipboard code: var redirecturl:string = "/http Www.somedomain.com?loggedin=true&username=Gus "; Sendtourl ("Http://www.myothersite.com?returnurl=" + Escape (RedirectURL)); 6.unescape () function
as3.0 syntax: Public function unescape (str:string): String
Evaluates the parameter str:string as a string, decodes the string from the URL-encoded format (converts all hexadecimal sequences to ASCII characters), and returns the string.
Parameters: str:string--the hexadecimal sequence string to escape
Return: String
Instance:
The following example shows the conversion process to escape to the reverse escape: Copy Content to Clipboard code: var email:string = "user@somedomain.com"; Trace (email); var escapedemail:string = escape (email); Trace (Escapedemail); var unescapedemail:string = unescape (Escapedemail); Trace (Unescapedemail); |