根据汉字获得其对应区位码时,需要使用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); |