当前位置: 移动技术网 > IT编程>开发语言>c# > C#把UNICODE编码转换为GB编码的实例

C#把UNICODE编码转换为GB编码的实例

2019年07月18日  | 移动技术网IT编程  | 我要评论

实例如下:

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), 16);
          int code2 = convert.toint32(word.substring(2), 16);
          codes[0] = (byte)code2;
          codes[1] = (byte)code;
          text = text.replace(v, encoding.unicode.getstring(codes));
        }
      }
      else
      {

      }
      return text;
    }

以上这篇c#把unicode编码转换为gb编码的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网