閱讀389 返回首頁    go 阿裏雲 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中查詢係統時間