AS3 Encoding conversion function __ garbled problem

Source: Internet
Author: User
Tags at sign resource valid alphanumeric characters

AS3 code conversion function Tags: Functions, coding

as3.0 new public class functions, similar to the use of JavaScript in the escape, encodeURI, encodeuricomponent, etc. ...

1.decodeURI () function [as3.0 added]

as3.0 syntax: Public function decodeURI (uri:string): String

Syntax: Public function decodeURI (uri:string): String

Returns the encoded form of a 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 "?". Use decodeURIComponent to encode these characters.

Input and output
%23 #
%24 $
%26 &
%2B +
%2C,
%2F/
%3A:
%3b;
%3d =
%3f?
%40 @

Parameters:

uri:string--A string representing the encoded URI.

Back: String

Instance: copying 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=&lt;user name= ' Some user ' ></user>
}
}
}
}
2.decodeURIComponent () function [as3.0 added]

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.

Back: String

Instance: copying content to Clipboard code:???
3.encodeURI () function [as3.0 added]

as3.0 syntax: Public function encodeURI (uri:string): String

Returns a string that is 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 "?". Use encodeURIComponent to encode these characters.

Non-encoded:

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 representing the encoded URI

Back: string copy content 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 added]

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--represents a string that encodes the URI component.

Back: String

Instance: copying content to Clipboard code:???
5.escape () function

as3.0 syntax: Public function Escape (str:string): String

Returns a coded 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 are replaced with the% hexadecimal sequence (characters). Percent semicolon (%) when used in a URL-encoded string Used to introduce an escape character, not with the modulo operator (%) Equivalent.
Parameters:
str:string--any string object or text that is to be encoded (an expression that is converted to a string and encoded in a URL-encoded format)

Back: String

Instance one: Copy content to Clipboard code://The following code generates results 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 the%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


Computes the parameter str:string as a string, decodes the string from the URL encoding format (converts all hexadecimal sequences to ASCII characters), and returns the string.

Parameters:
str:string--the hexadecimal sequence string to escape

Back: String

Instance:

The following example shows the conversion process escaping to a reverse escape: copying content to the Clipboard code: var email:string = "user@somedomain.com";
Trace (email);
var escapedemail:string = escape (email);
Trace (Escapedemail);
var unescapedemail:string = unescape (Escapedemail);
Trace (Unescapedemail);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.