public static string GetEncodingString(string srcString)
{
Encoding e8859Encode = Encoding.GetEncoding("iso-8859-1");
Encoding srcEncode = Encoding.GetEncoding("gb2312");
Encoding dstEncode = Encoding.Unicode;
byte[] srcBytes = e8859Encode.GetBytes(srcString);//用iso-8859-1去转换源字符串
byte[] dstBytes = Encoding.Convert(srcEncode, dstEncode, srcBytes);//但是,是从gb2312转到unicode的
char[] dstChars = new char[dstEncode.GetCharCount(dstBytes, 0, dstBytes.Length)];
dstEncode.GetChars(dstBytes, 0, dstBytes.Length, dstChars, 0);
return new string(dstChars);
}
具体原因我推测是因为数据过来是ISO-8859-1,但.Net底层处理成了Gb2312了,所以需要通过两种编码转换成Unicode才能正常显示,听说在Java中只要new String(s.getBytes("ISO-8859-1"),"gb2312");就OK了。
---------------------------------------------------------
专注移动开发
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2008-02-27 21:30
TiGERTiAN 阅读(3551)
评论(11) 编辑 收藏 所属分类:
DotNet 、
MapXtreme