区位码和汉字互转
//由区位码转为汉字.
//"D3EA"相对于汉字"雨"
System.Text.Encoding gb = System.Text.Encoding.GetEncoding("gb2312");
byte[] bytes = new byte[]{ Convert.ToByte("d3",16),Convert.ToByte("ea",16)};
string strResult = gb.GetString( bytes );
MessageBox.Show( strResult );
//由汉字转为区位码
//将"雨"字转为相对的区位码(16进制)
bytes = gb.GetBytes( strResult );
string strTemp = " " ;
for( int i = 0 ;i<bytes.Length; i++)
{
strTemp += Convert.ToString( bytes[i],16 ) + " ";
}
MessageBox.Show(strTemp.Trim());
参考:
GB2312简体中文编码表
http://www.aspxboy.com/1885/archive.aspx