C#获得汉字对应区位码

来源:互联网 发布:在线网络名片制作 编辑:程序博客网 时间:2024/04/29 11:23
 根据汉字获得其对应区位码时,需要使用System.Text.Encoding类中Default编码方式的GetBytes方法对给出的汉字进行编码。获得汉字区位码的关键代码如下:
byte[] array = new byte[2];
array = System.Text.Encoding.Default.GetBytes("" + textBox1.Text.Trim() + "");
int front =(short)(array[0]-'/0');
int back =(short)(array[1]-'/0');
textBox2.Text = Convert.ToString(front-160) + Convert.ToString(back-160);