Unicode Chinese transcoding function code

Source: Internet
Author: User
Really do not understand TX, user name coding unexpectedly return the value is not the same, such as "Leilei 52D", there are the following two kinds of return? Leilei 52D and%01%u96f7%u78ca%0152d. It's pretty depressing. Fortunately, TX also has the return of Chinese names, the decoding process is omitted, but still recorded.
Copy CodeThe code is as follows:
<summary>
Unicode character converts to Chinese characters, such as 96F7,78CA, etc.
</summary>
Private char Unicodetochinesebyhex (string Unicode)
{
return (char) int. Parse (Unicode, System.Globalization.NumberStyles.HexNumber);
}

<summary>
Unicode character converts to Chinese characters, such as 96f7,78ca
Note: Decoding from the back forward
</summary>
private string Unicodetochinese (String Unicode)
{
byte[] array = new BYTE[UNICODE.LENGTH/2];

for (int i = 0; i < array. Length; i++)
{
string S1 = unicode.substring (Unicode.length-(i + 1) * 2, 2);
int T1 = Convert.ToInt32 (S1, 16);
Array[i] = (byte) t1;
}

return System.Text.Encoding.Unicode.GetString (array);
}

<summary>
Converts to Unicode characters such as ' thunder '
</summary>
private string Chinesetounicode (char Chinese)
{
return ((int) Chinese). ToString ("X");
}


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.