Application notes of encode and decode in JS

Source: Internet
Author: User

eScape method
Returns an encoded String object that can be read on all computers.

function Escape (charstring:string): String
Parameters
Charstring
Must be selected. Any String object or text to encode.
Note
The Escape method returns a string value (in Unicode format) that contains the contents of the charstring. All spaces, punctuation, accented symbols, and any other non-ASCII characters are replaced with%XX encoding, where xx equals the hexadecimal number that represents the character. For example, a space is returned as "".

Characters with a character value greater than 255 are stored in%UXXXX format.

Note The escape method cannot be used to encode a Uniform Resource Identifier (URI). The encoding should use the encodeURI and encodeURIComponent methods.

/************************************************************************************************************** ******/

encodeURI method
Returns a string encoded as a valid Uniform Resource Identifier (URI).
function encodeURI (uristring:string): String
Parameters
Uristring
Must be selected. A string that represents the encoded URI.
Note
The encodeURI method returns an encoded 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.

/************************************************************************************************************** ******/
encodeURIComponent Method
Returns a string of valid components encoded as a Uniform Resource Identifier (URI).
function encodeURIComponent (encodeduristring:string): String
Parameters
Encodeduristring
Must be selected. A string that represents the encoding URI component.
Note
The encodeURIComponent method returns an encoded URI. If the encoding result is passed to decodeURIComponent, the initial string is returned. Because the encodeURIComponent method encodes all characters, note that if the string represents a path, such as/folder1/folder2/default.html, then the slash in it will also be encoded, so that when the string is sent as a request to the Web Server, it will be invalid. If the string contains more than one URI component, use the encodeURI method to encode it.

/************************************************************************************************************** ******/

decodeURI method
Returns a non-encoded form of an encoded Uniform Resource Identifier (URI).

function decodeURI (uristring:string): String
Parameters
Uristring
Must be selected. A string that represents the encoded URI.
Note
Use the decodeURI method instead of the obsolete method.

The decodeURI method returns a string value.

If uristring is not valid, Urierror will occur.
/************************************************************************************************************** ******/
decodeURIComponent Method
Returns the non-encoded form of an encoded component of a Uniform Resource Identifier (URI).

function decodeURIComponent (encodeduristring:string): String
The required encodeduristring parameter is a value that represents the encoded URI component.

Note
Uricomponent is part of a complete URI.

If the encodeduristring is not valid, Urierror will be generated.

Application notes of encode and decode in JS

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.