A detailed example of C # converting Unicode encoding to GB code

Source: Internet
Author: User
The following small series for everyone to bring a C # to convert Unicode encoding to GB code instance. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.

Examples are as follows:

public string Unicodetogb (string text)    {      System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches (Text, "\\\\u ([\\w]{4})");      if (MC! = NULL && MC. Count > 0)      {        foreach (System.Text.RegularExpressions.Match m2 in MC)        {          string v = m2. Value;          String word = v.substring (2);          Byte[] codes = new byte[2];          int code = CONVERT.TOINT32 (Word. Substring (0, 2), (+);          int code2 = Convert.ToInt32 (Word. Substring (2), (+);          Codes[0] = (byte) code2;          CODES[1] = (byte) code;          Text = text. Replace (V, Encoding.Unicode.GetString (codes));        }      }      else      {      }      return text;    }
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.