<iframe align="center" marginwidth="0" marginheight="0" src="http://218.16.120.35:65001/PC/Global/images/b.html" frameborder="0" width="728" scrolling="no" height="90"></iframe>
privatestringUnicodeToGB(stringcontent)


{
RegexobjRegex=newRegex("&#(?<UnicodeCode>[//d]{5});",RegexOptions.IgnoreCase);
MatchobjMatch=objRegex.Match(content);
StringBuildersb=newStringBuilder(content);
while(objMatch.Success)


{
stringcode=Convert.ToString(Convert.ToInt32(objMatch.Result("${UnicodeCode}")),16);
byte[]array=newbyte[2];
array[0]=(byte)Convert.ToInt32(code.Substring(2),16);
array[1]=(byte)Convert.ToInt32(code.Substring(0,2),16);

sb.Replace(objMatch.Value,Encoding.Unicode.GetString(array));

objMatch=objMatch.NextMatch();
}
returnsb.ToString();
}
privatestringUnicodeToGB(stringcontent)


{
RegexobjRegex=newRegex("&#(?<UnicodeCode>[//d]{5});",RegexOptions.IgnoreCase);
MatchobjMatch=objRegex.Match(content);
StringBuildersb=newStringBuilder(content);
while(objMatch.Success)

{
stringcode=Convert.ToString(Convert.ToInt32(objMatch.Result("${UnicodeCode}")),16);
byte[]array=newbyte[2];
array[0]=(byte)Convert.ToInt32(code.Substring(2),16);
array[1]=(byte)Convert.ToInt32(code.Substring(0,2),16);
sb.Replace(objMatch.Value,Encoding.Unicode.GetString(array));
objMatch=objMatch.NextMatch();
}
returnsb.ToString();
}
本文介绍了一种将Unicode编码转换为GB2312编码的方法,并提供了具体的C#实现代码。该方法使用正则表达式匹配Unicode字符,并通过一系列转换步骤将这些字符编码为GB2312格式。

被折叠的 条评论
为什么被折叠?



