本文摘自PHP中文网,作者黄舟,侵删。
下面小编就为大家带来一篇C#把UNICODE编码转换为GB编码的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧实例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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编码的示例代码的详细内容!
相关阅读 >>
C#开发实例-订制屏幕截图工具(十)在截图中包含鼠标指针形状
C#使用socket创建一个小型的web server代码分享
C#怎么学
详解C#读取xml多级子节点的示例代码
C#之正则表达式介绍
C#如何将datatable中的列名复制到另一个datatable
C#使用autoresetevent实现同步的详解及实例
C#中list的用法
asp.net实现分页(非控件,输出html代码)
详解C#中抽象类与接口的区别
更多相关阅读请进入《C#》频道 >>
清华大学出版社
作者:[美]克里斯琴·内格尔(Christian Nagel)著。出版时间:2019年3月。
转载请注明出处:木庄网络博客 » 详解C#把UNICODE编码转换为GB编码的示例代码