C 按漢字拼音首字母排序

2021-06-29 08:14:53 字數 1714 閱讀 6771

可參考以下部落格。

c# 使用微軟的visual studio international pack 類庫提取漢字拼音首字母 - 影子科技 -

c#漢字轉換拼音技術詳解(高效能) - 歷史的驅動 -

按漢字的拼音排序(c#實現) - 焦濤 -

漢字轉換為漢語拼音(全拼/首字母簡拼) - 任家 -

一、首先將漢字轉為拼音首字母縮寫

使用微軟提供的方法獲取到的是全拼再擷取,故效率較低,以下為最終使用的**。

public

static

string getfirstpy(stringstr)

return ret;

}private

static

string getpychar(charc)

byte array = new

byte[2];

array = system.text.encoding.default.getbytes(str);

int i = (short)(array[0]- '\0') * 256 + ((short)(array[1]- '\0'));

if (i < 0xb0a1) return

"*";

if (i < 0xb0c5) return

"a";

if (i < 0xb2c1) return

"b";

if (i < 0xb4ee) return

"c";

if (i < 0xb6ea) return

"d";

if (i < 0xb7a2) return

"e";

if (i < 0xb8c1) return

"f";

if (i < 0xb9fe) return

"g";

if (i < 0xbbf7) return

"h";

if (i < 0xbfa6) return

"j";

if (i < 0xc0ac) return

"k";

if (i < 0xc2e8) return

"l";

if (i < 0xc4c3) return

"m";

if(i < 0xc5b6) return

"n";

if (i < 0xc5be) return

"o";

if (i < 0xc6da) return

"p";

if (i < 0xc8bb) return

"q";

if (i < 0xc8f6) return

"r";

if (i < 0xcbfa) return

"s";

if (i < 0xcdda) return

"t";

if (i < 0xcef4) return

"w";

if (i < 0xd1b9) return

"x";

if (i < 0xd4d1) return

"y";

if (i < 0xd7fa) return

"z";

return

"*";

} 二、構建乙個list,儲存漢字和其對應拼音縮寫,然後排序。

str = str.orderby(x => x.pinyin).tolist();

即可獲得排序後的列表。

漢字轉拼音首字母

public string hz2py string hz 獲得漢字的區位碼 else if tmp 45253 tmp 45760 else if tmp 47761 tmp 46317 else if tmp 46318 tmp 46825 else if tmp 46826 tmp 47009...

獲取漢字拼音首字母

有個專案需要用到生成漢字的首字母,但從網上查了一下,對於多音字的處理都不是很好,所以就利用pinyin4j這個工具包自己寫了乙個。用到的jar包是pinyin4j 2.5.0.jar 獲取拼音首字母,多音字用逗號隔開 public static string getfirstspell string...

獲取漢字拼音首字母

unit py inte ce uses sysutils 獲取漢字的拼音首字元,這個函式將用在getpyindexstr 中.function getpyindexchar strchinese string bupcase boolean true char 獲取多個漢字的拼音首字元組成的字串....