问题描述:通过Server Studio从Informix数据库中读出的数据中文显示正常,但是通过C#读出绑定到GridPanel中文显示乱码
解决方案:
1
2
3
4
5
6
7
8
9
10
11
12
|
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);
}
|
参考文:http://www.blogjava.net/TiGERTiAN/archive/2008/02/27/182558.html