阅读389 返回首页    go 技术社区[云栖]


C#汉字求汉字编码

private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                char chrWord = Convert.ToChar(txtWord.Text);             //获取一个汉字
                byte[] gb2312 = Encoding.GetEncoding("GB2312").GetBytes(
                    new char[] { chrWord });                             //获得编码字节序列
                int n = (int)gb2312[0] << 8;                             //第一个字节序列左移8位
                n += (int)gb2312[1];                                     //得到汉字编码     
                txtCode.Text = n.ToString();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

最后更新:2017-04-02 00:06:49

  上一篇:go C++ switch-case语句应用经验讲解
  下一篇:go Mysql中查询系统时间