中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

C# 計(jì)算輸入漢字的GBK編碼,十六進(jìn)制數(shù)輸出

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用
C# 計(jì)算輸入漢字的GBK編碼,十六進(jìn)制數(shù)輸出
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace getCode
{
    class Program
    { 
&nbsp;       /// <summary>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// 計(jì)算輸入漢字對應(yīng)的GBK編碼主函數(shù)入口
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// </summary>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// <param name="args">< /param>&nbsp;static void Main(string[] args)
        {
            try
            {
                while (true)
                {
                    char cWord = (char)Console.Read();//讀入一個(gè)漢字
                    byte[] bGb2312 = Encoding.GetEncoding("gbk").GetBytes(new Char[] { cWord });//<span id="mt1" class="sentence" data-guid="21b4c66a1cae34f4812147989864f337" data-source="Returns the encoding associated with the specified code page name.">返回gbk的編碼</span>對象的字節(jié)數(shù)組,包含對cWord進(jìn)行編碼的結(jié)果。
                    int n = (int)bGb2312[0] << 8;//第一個(gè)字節(jié)左移八位
                    n += (int)bGb2312[1];
                    Console.WriteLine("漢字{0}的gbk編碼為:{1,4:x4}" ,cWord, n);//輸出漢字對應(yīng)是十六進(jìn)制GBK編碼
                    Console.ReadKey();
                }
            }
            catch
            {
               Console.WriteLine("輸入錯(cuò)誤!請輸入漢字字符!");
          }
        }
    }
}
 

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:PHP計(jì)算指定文件夾的信息(文件夾數(shù),文件數(shù),文件夾大小)

下一篇:C#在服務(wù)器端裁剪圖片代碼