日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > C# >内容正文

C#

C# ASCII码字符转换

發(fā)布時(shí)間:2023/12/31 C# 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# ASCII码字符转换 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

C#單純的字母數(shù)字ASCII碼轉(zhuǎn)換

字母轉(zhuǎn)換成數(shù)字

byte[] array = new byte[1]; //定義一組數(shù)組array array = System.Text.Encoding.ASCII.GetBytes(string); //string為待轉(zhuǎn)換的字母 int asciicode = (short)(array[0]); //asciicode 為整數(shù)ASCII碼 ASCII碼 = Convert.ToString(asciicode); //將轉(zhuǎn)換一的ASCII碼轉(zhuǎn)換成string型

數(shù)字轉(zhuǎn)換成字母(1)

byte[] array = new byte[1]; array[0] = (byte)(Convert.ToInt32(ASCII碼)); //ASCII碼強(qiáng)制轉(zhuǎn)換二進(jìn)制 string str=Convert.ToString(System.Text.Encoding.ASCII.GetString(array));//str為ASCII碼對應(yīng)的字符

數(shù)字轉(zhuǎn)換成字母(2)

System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); byte[] byteArray = new byte[] { (byte)ASCII碼 }; string str = asciiEncoding.GetString(byteArray);

實(shí)例:

string sVer = ""; string strCheck = "10C"; string sLetter = strCheck.Substring(2, 1); // 獲取strCheck第三位的字符// 獲取sLetter資訊的Ascii碼 byte[] array = new byte[1]; //定義一組數(shù)組array array = System.Text.Encoding.ASCII.GetBytes(sLetter); //string轉(zhuǎn)換的字母 int nAsciicode = (short)(array[0]);// 判斷是不是大寫字母 if (nAsciicode <= 65 || nAsciicode >= 90) continue;// 判斷sLetter字母前的所有大寫字母 for (int k = 65; k < nAsciicode; k++) {// 將Ascii碼轉(zhuǎn)化為大寫字母System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();byte[] byteArray = new byte[] { (byte)k };string strCharacter = asciiEncoding.GetString(byteArray);// 拼接版本.if (sVer == ""){if (strCheck.Length == 3){sVer = strCheck.Substring(0, 2) + strCharacter ;}else{sVer = strCheck.Substring(0, 2) + strCharacter + strCheck.Substring(3, strCheck.Length - 3);}}else{if (strCheck.Length == 3){sVer += "," + strCheck.Substring(0, 2) + strCharacter;}else{sVer += "," + strCheck.Substring(0, 2) + strCharacter + strCheck.Substring(3, strCheck.Length - 3);}}}

上面實(shí)例運(yùn)行結(jié)果應(yīng)為:10A,10B

千里之行始于足下,原共勉之!

總結(jié)

以上是生活随笔為你收集整理的C# ASCII码字符转换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。