C # Chinese and Unicode character conversion methods

Source: Internet
Author: User

This is actually a lot of things to see, especially when using JSON more,
In fact, it's very simple. The main use of the ToString ("x") method
Just look at the code.

stringstr ="Hello, I'm zhe."; stringOUTSTR =""; if(!string. IsNullOrEmpty (str)) { for(inti =0; I < Str. Length; i++)                {                    //converts a Chinese character to a 10-based integer and then to a 16-Unicode characterOutstr + ="\\u"+ ((int) str). ToString ("x"); }            }

Here's how to turn Unicode data into Chinese
Like the following data, for example.
\u8c01\u80fd\u591f\u7ed9\u6211\u98ce\u9669\u6295\u8d44\u54e6!\u6211\u60f3\u501f\u5341\u4e07\u529e\u4e00\u4e2a\ U517b\u6b96\u5382\u3002\u6211\u53ef\u662f\u6709\u5bb6\u5ead\u62c5\u4fdd\u7684\u54e6!#\u4e0a\u7f51\u7231\u901b\ U4ec0\u4e48
Here is mainly the use of the Parse method
Let's see how it's achieved.

Private voidForm1_Load (Objectsender, EventArgs e) {            stringstr =@"\u8c01\u80fd\u591f"; STR=unicontostring (str); }        /// <summary>        ///Convert Unicon string to Chinese character string/// </summary>        /// <param name= "str" >Unicon String</param>        /// <returns>Kanji String</returns>         Public stringUnicontostring (stringstr) {            stringOUTSTR =""; if(!string. IsNullOrEmpty (str)) {string[] strlist = str. Replace ("\\",""). Split ('u'); Try                {                     for(inti =1; I < Strlist. Length; i++)                    {                        //converts a Unicode character to a 10-in integer and then to char Chinese charactersOutstr + = (Char)int.                    Parse (Strlist, System.Globalization.NumberStyles.HexNumber); }                }                Catch(FormatException ex) {outstr=Ex.                Message; }            }            returnoutstr; }

in the edit box, fill in the \u7b2c01\u96c6 string temp = txturl.text; Console.WriteLine (uri.unescapedatastring ("\u7b2c01\u96c6")); Only this can decode Console.WriteLine (uri.unescapedatastring (temp)); Console.WriteLine (Httputility.urldecode (temp, Encoding.UTF8));

C # Chinese and Unicode character conversion methods

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.