C 漢字轉拼音

2022-05-06 09:51:08 字數 1104 閱讀 3114

其實這兩個dll 任何乙個都可以實現漢字轉拼音,然而 npinyin.dll 收錄的漢字並不全,但是很人性化,能識別一些常用的漢字。chncharinfo.dll 是微軟的很全但是不人性化。另外本套**外有乙個自己維護的個別漢字檔案,例如一些多音字姓氏。

本程式的使用場景是姓名轉拼音,所以先判斷第乙個漢字是否在自己維護的拼音庫中存在,如果存在者優先使用這個庫中漢字所對應的拼音,如果不存在者優先使用npinyin庫中轉化拼音的方法,轉化失敗再使用微軟提供的chncharinfo中轉拼音的方法。

main函式

static void main(string args)

pinyinhelper類

public class pinyinhelper

if (pinyin.length == 0)

}return fullspell.tostring().tolower();}}

catch (exception e)

return string.empty;

}/// /// 漢字轉首字母

///

///

///

public static string getfirstspell(string strchinese)

return fullspell.tostring().toupper();}}

catch (exception e)

return string.empty;

}private static string getspell(char chr)}}

return coverchr;

}/// /// 從字典獲取拼音

///

/// 字

/// 字典

///

private static string getfrompinyindic(char c, idictionarypinyindic)

return pinyindic[c];}}

接下來是本程式維護的 pinyindic.txt,該檔案放在"\bin\debug"目錄下,當然也可以不使用。

C 漢字轉拼音

region 獲取漢字的全拼 getpinyin 和拼音首字母 getcodstring region 屬性資料定義,漢字的機內碼陣列,機內碼對應的拼音陣列 漢字的機內碼陣列 private static int pyvalue newint 機內碼對應的拼音陣列 private static st...

C 漢字轉拼音

1 using system 2using system.collections.generic 3using system.linq 4using system.text 56 namespace common 7,13 14 15 16 17 18 19 20 21 22 23 24 25 26...

C 漢字轉拼音

其實這兩個dll 任何乙個都可以實現漢字轉拼音,然而 npinyin.dll 收錄的漢字並不全,但是很人性化,能識別一些常用的漢字。chncharinfo.dll 是微軟的很全但是不人性化。另外本套 外有乙個自己維護的個別漢字檔案,例如一些多音字姓氏。本程式的使用場景是姓名轉拼音,所以先判斷第乙個漢...