实例如下:
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编码的示例代码的详细内容。