網路上找到的文章大部份提到的中文範圍是U+4E00 ~ U+9FA5,
這篇文章
更詳細,把不同的Unicode版本也標上去。
接下來則是寫一個小程式測試字串對應的code point。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Console
class Program
static void Main(string[] args)
//假設特定字串如下
string subject = "?? 國文(一) Web Development 網路發展";
char[] charArr = subject.ToCharArray();
for (int counter = 0; counter < charArr.Length; counter++)
int intValue = Convert.ToInt32(charArr[counter]);
string strHex = String.Format("{0:X}", intValue);
System.Console.WriteLine("字元: {0}, 十進位: {1}, 十六進位: {2}", charArr[counter].ToString(), intValue, strHex);
System.Console.Read();
執行的結果如下,
程式碼說明:
設定的字串裡,有中文、英文、空白,還有全形中文。
.NET的Unicode是UTF-16,而字元是以System.Char結構呈現。
Char是對應到16位元的數值,十六進位的範圍是0x0000 ~ 0xffff。
詳細內容請看
這裡
。
程式把字串轉為字元陣列後,顯示每個字元的十進位和十六進位。
從執行的超果可以看到,中文「一」的十六進位是4E00,
正好是中文code point的開頭。
以上,做為記錄。