Unicode and Chinese characters transcoding each other

Source: Internet
Author: User
Tags foreach

\uxxxx This format is a Unicode notation that represents a character in which XXXX represents a 16-digit, range-0~65535. Unicode hexadecimal numbers can only contain numeric 0~9, uppercase letters A~F, or lowercase a~f. It is important to note that the size-to-end problem of Unicode, which is usually small-ended, such as \u5c0f, which represents the ' small ' word in Chinese, is converted to 10 binary is 9215, so the byte array should be 1592. Kanji to Unicode

private string Unicode2chinese (string strunicode)
{
    string[] splitstring = new string[1];
    Splitstring[0] = "\\u";
    string[] Unicodearray = Strunicode.split (splitstring, stringsplitoptions.removeemptyentries);
    StringBuilder sb = new StringBuilder ();

    foreach (string item in Unicodearray)
    {
        byte[] codes = new byte[2];
        int Code1, Code2;
        Code1 = Convert.ToInt32 (item. Substring (0, 2), (+);
        Code2 = Convert.ToInt32 (item. Substring (2), (+);
        Codes[0] = (byte) code2;//must be small end in front
        codes[1] = (byte) code1;
        Sb. Append (Encoding.Unicode.GetString (codes));
    }

    Return SB. ToString ();
}
Unicode to Kanji
private string Chinese2unicode (String Strchinese) {string strunicodes = string.
    Empty; foreach (char item in Strchinese.tochararray ()) {strunicodes + = "\\u" + ((int) item). ToString ("X");
16 binary} return strunicodes; }

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.