JavaScript converts Unicode encoding to Chinese

Source: Internet
Author: User
Tags uppercase letter

Var

The following methods are commonly used in the conversion of such data to Chinese issues.

1. Eval parsing or new Function ("' + str + ')" ()

// "I am a Unicode encoding"

2. Unescape parsing

// "I am a Unicode encoding"
 C # Chinese and Unicode character conversion methods

Decoding

 Public stringUncode (stringstr) {              stringOUTSTR =""; Regex Reg=NewRegex (@"(? i)//u ([0-9a-f]{4})"); Outstr= Reg. Replace (str,Delegate(Match M1) {return((Char) Convert.ToInt32 (M1. groups[1]. Value, -)).              ToString ();              }); returnoutstr; }  

C #/// <summary>    ///convert Kanji to Unicode/// </summary>    /// <param name= "text" >the string to convert</param>    /// <returns></returns>     Public Static stringGbtounicode (stringtext) {        byte[] bytes =System.Text.Encoding.Unicode.GetBytes (Text); stringLowcode ="", temp ="";  for(inti =0; I < bytes. Length; i++)        {            ifI2==0) {Temp= System.Convert.ToString (Bytes[i], -);//remove element 4 encoded content (two bit 16 binary)                if(temp. Length <2) temp ="0"+temp; }            Else            {                stringMytemp = Convert.ToString (Bytes[i], -); if(Mytemp. Length <2) Mytemp ="0"+ mytemp; Lowcode = Lowcode +@"\u"+ mytemp + temp;//remove element 4 encoded content (two bit 16 binary)            }        }        returnLowcode; }    /// <summary>    ///convert Unicode to kanji/// </summary>    /// <param name= "name" >the string to convert</param>    /// <returns></returns>     Public stringUNICODETOGB (stringtext) {MatchCollection MC= Regex.Matches (Text,"([\\w]+) | (\\\\u ([\\w]{4}))"); if(MC! =NULL&& MC. Count >0) {StringBuilder sb=NewStringBuilder (); foreach(Match m2inchMC) {stringv =m2.                Value; stringWord = v.substring (2); byte[] codes =New byte[2]; intCode = Convert.ToInt32 (Word. Substring (0,2), -); intCode2 = Convert.ToInt32 (Word. Substring (2), -); codes[0] = (byte) Code2; codes[1] = (byte) code; Sb.            Append (Encoding.Unicode.GetString (codes)); }            returnsb.        ToString (); }        Else        {            returntext; }}js<script language=javascript>varclassobj={tounicode:function (str) {returnEscape (str). replace (/%/g,"\\"). toLowerCase (); }, Ununicode:function (str) {returnUnescape (Str.replace (/\\/g,"%")); }, Copyingtxt:function (str) {document.getElementById (str).Select(); Document.execcommand ("Copy"); }    }</script><textarea Id=codes style="width:500px;height:300px"></textarea><br><br><input Type=button Value=unicode Encryption onclick=javascript:codes.value= Classobj.tounicode (codes.value) ><input Type=button Value=unicode decryption onclick=javascript:codes.value= Classobj.ununicode (codes.value) ><input Type=button value= Copy the above text Onclick=javascript:classobj.copyingtxt ("Codes") ><input Type=button value= Empty the above contents onclick=javascript:codes.value="">Java: Public Static voidMain (string[] args) {String str="\U4E2D\U534E\U4EBA\U6C11\U5171\U548C\U56FD"; //char[] Chararray = Str.tochararray (); //str = new String (chararray);System. out. println (str); System. out. Print (Str.equals ("China")); }

Unicode Mini-Encyclopedia:

In the field of computer science, Unicode (Uniform Code, universal Code, single code, standard universal Code) is a standard in the industry, it can enable the computer to present the world's dozens of kinds of text system. Unicode is developed on the basis of the universal Character set (Universal Character set) and is also in the form of books (the Unicode Standard, currently fifth edition published by Addison-wesley Professional , isbn-10:0321480910) published externally. Unicode contains more than 100,000 characters (in 2005, the 100,000th character of Unicode is adopted and recognized as one of the criteria), a set of code diagrams that can be used as a visual reference, a set of coding methods and a set of standard character encodings, a set of characters including superscript, subscript, and so on.

The Unicode organization (the Unicode Consortium) is operated by a non-profit organization and dominates the subsequent development of Unicode, with the goal of replacing the existing character encoding scheme with a Unicode encoding scheme, In particular, the existing programmes in the multilingual environment, there are only limited space and incompatible problems.

The success of Unicode in the recognition of character sets enables it to be widely and highly advantageous in the field of internationalization and localization of computer software. This standard has been adopted in a variety of new technologies in recent years, including extensible Labeling Language (XML), the Java programming language, and the latest operating systems.

Encoding rules for Unicode encoding

For example, to encode "Yang", we can create a new Notepad, enter "Yang" Save as a Unicode encoding, and then view the file binary content, the previous FF fe two bytes is the Unicode encoded file header flag, followed by the 68 672 bytes is "yang" Unicode encoding, The conversion of the calculator to decimal is 26472, you can now write "Yang" in an HTML file, ie opens to show a "yang" word.

Of course, for a generic ASCII code, Unicode encoding is consistent with ASCII encoding, so a can display an uppercase letter "a".

JavaScript converts Unicode encoding to Chinese

Related Article

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.