Differences between encodeuri, encodeuricomponent, and escape

Source: Internet
Author: User
Tags alphanumeric characters

There are three functions in as3 that can encode strings: Escape, encodeuri, and encodeuricomponent. The corresponding three decoding functions are: Unescape, decodeuri, and decodeuricomponent.


1Public Function escape (STR: string): String

 

Convert the parameter to a string and encode it in URL encoding format. in this format, most non-alphanumeric characters are replaced with the % hexadecimal sequence. When a string is used for URL encoding, the percent sign (%) is used to introduce escape characters, which is not equivalent to the modulo operator (%.

The following table shows all characters that are not converted from the escape () function to the escape sequence.

Unencoded characters

 

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
 
@-_. * +/



Parameter STR: String-the expression to be converted to a string and encoded in URL encoding format.

 

Returns a string-a URL-encoded string.

 

2Public Function encodeuri (URI: string): String

Encodes a string into a valid uri (Uniform Resource Identifier ). Converts a complete URI to a string where all characters except those that belong to a group of basic characters are encoded in a UTF-8 escape sequence.

The following table shows the entire set of basic characters that are not converted from the encodeuri function to the UTF-8 escape sequence.

Unencoded characters

 

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
;/? : @ & =+ $ ,#
-_.! ~ *'()



Parameter URI: String-a string that represents the complete Uri.

 

 

Returns a string-a string where some characters are encoded as UTF-8 escape sequences.

Example

    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 encoded:String = encodeURI(uri);            var decoded:String = decodeURI(encoded);            trace(uri);        // http://www.example.com/application.jsp?user=<user name=‘some user‘></user>            trace(encoded);    // http://www.example.com/application.jsp?user=%3Cuser%20name=‘some%20user‘%3E%3C/user%3E            trace(decoded);    // http://www.example.com/application.jsp?user=<user name=‘some user‘></user>        }    }

  

3Public Function encodeuricomponent (URI: string): String

 

Encodes a string into a valid URI component. Converts a substring of a URI into a string that is encoded in a UTF-8 escape sequence except for characters that belong to a very small set of basic characters.

The encodeuricomponent () function is different from the encodeuri () function. It is only applicable to a part of a URI string (called a URI component ). The URI component indicates any text between some special characters,

These special characters are called component separators (: //; and? ). "HTTP" and "www.adobe.com" are common URI component examples.

Another important difference between this function and encodeuri () is that, since this function assumes that it processes the URI component, it will separate the Special Separator characters (;/? : @ & =+ $, #) Is the regular text to be encoded.

The following table shows all characters that are not converted from the encodeuricomponent function to the UTF-8 escape sequence.

 

Unencoded characters

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
-_.! ~ *'()
 



Parameter URI: String

Returns string

 

Conclusion: 1 if you want to encode all a URI, use the encodeuri function.

2 If you want to transfer parameters in the URI, especially Chinese parameters and special characters, use the encodeuricomponent function.

3 In addition to ASCII letters, numbers, and specific symbols, escape () encodes all input strings. Therefore, it is best not to use this method to encode URLs.

4. If Tomcat can parse escape, but WebSphere cannot parse it, the URL Resource (for example, 1.swf) cannot be found ).

Differences between encodeuri, encodeuricomponent, and escape

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.