Javascript Chinese escape characters

Source: Internet
Author: User

Similar to escape (), which is represented by a set of numbers XXX later is the hexadecimal number encoded in the character set table, that is, % XXXX and/uxxxx indicate the same, for example, if the hexadecimal 5ba0 value is input, it can be expressed by/u5ba0 or % u5ba0, and the number is 23456 in decimal format, the conversion using Unicode rules is "Pet" Chinese characters. That is, the results are different based on different rules, which is also given by the rule creator.

Another example is that 155 is converted from octal to decimal to 1*64 + 5*8 + 5 = 109.

String. fromcharcode (109) === "M"

There are a total of 256 octal or hexadecimal escape characters.

The fixed format of hexadecimal escape characters is (2 digits ):

\ X hexdigit

The conversion functions are provided below.

VaR chineseascode = {on: function (STR) {var arr = []; var hex; For (VAR I = 0; I <Str. length; I ++) {hex = ("00" + Str. charcodeat (I ). tostring (16 )). slice (-4); arr. push (HEX);} return "\ U" + arr. join ("\ U") ;}, UN: function (STR) {return Unescape (Str. replace (// \/g, "% "));}};

Reference JavaScript octal Escape Character http://cmc3.cn/n/258.html

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.