Differences between encodeURI, encodeURIComponent, and escape and _ javascript skills

Source: Internet
Author: User
Tags encode string
EncodeURI, encodeURIComponent, and escape are all used for encoding. This article will introduce the differences and Applications of encodeURI, encodeURIComponent, and escape. If you are interested, let's study together. First, we all know that these three items are used for encoding. First, encodeURI () and encodeURIComponent () are used for encoding and decoding during url conversion.

If there is encoding, there will be decoding. decoding is decodeURI () and decodeURIComponent (). Their usage is very simple. The purpose can be achieved by bringing the text to be transcoded into the parameters.

For example:

EncodeURI ("I am the text to be encoded ")
DecodeURI ("I am the text to be decoded ")
EncodeURIComponent ("I am the text to be encoded ")
DecodeURIComponent ("I am the text to be decoded ")

The difference between encodeURI () and encodeURIComponent () is not big.

The main difference is:

EncodeURI is not encoded with 82 characters :!, #, $, &, ', (,), *, +,-,.,/,:,;, = ,?, @,_,~, 0-9, a-z, A-Z

EncodeURIComponent has 71 unencoded characters :!, ',(,),*,-,.,_,~, 0-9, a-z, A-Z

EncodeURI is mainly used to assign values directly to the address bar:

Location. href = encodeURI ("http://www.cnblogs.com/Tezml ");

EncodeURIComponent is mainly used for url query parameters:

Location. href = "http://www.cnblogs.com/Tezml/test.php? A = "+ encodeURIComponent (" I am my ");

And escape is different from the two above.

Escape () is encoding, and unescape () is decoding;

Escape Method

Encode String objects so that they can be read on all computers,

Escape (charString)

The required charstring parameter is any String object or text to be encoded.

Description

The escape method returns a string containing the charstring content (in Unicode format ). All spaces, punctuation marks, accents, and other non-ASCII characters are replaced by % xx encoding,

Xx indicates the hexadecimal number of the character. For example, "% 20" is returned by a space ".

The characters with a value greater than 255 are stored in % uxxxx format.

Escape unencoded characters are 69: *, +,-,.,/, @, _, 0-9, a-z, A-Z

Note that the escape method cannot be used to encode the Uniform Resource Identifier (URI. Use the encodeURI and encodeURIComponent methods for encoding.

The last demo about encoding and decoding

  Tezml _ encoding and decoding Test 
  
  
  
  

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.