Unicode Chinese transcoding Function Code

Source: Internet
Author: User

I really don't know about TX. the user name encoding actually returns different values. For example, "Lei 52D", there are two types of returned values? Lei? 52D and % 01% u96F7 % u78CA % 0152D. Quite depressing. Fortunately, there is still a Chinese name returned for TX, which saves the process of decoding, but records it.
Copy codeThe Code is as follows:
/// <Summary>
/// Convert Unicode characters to Chinese characters, such as 96F7 and 78CA"
/// </Summary>
Private char UnicodeToChineseByHex (string Unicode)
{
Return (char) int. Parse (Unicode, System. Globalization. NumberStyles. HexNumber );
}

/// <Summary>
/// Convert Unicode characters to Chinese characters, such as 96F7 and 78CA
/// Note: decode the 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>
/// Convert Chinese characters to Unicode characters, such as 'Re'
/// </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.