下面小编就为大家带来一篇c#把unicode编码转换为gb编码的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
实例如下:
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编码的示例代码的详细内容。