Excel 取得漢字拼音首字母

2021-07-07 06:55:00 字數 2005 閱讀 5848

最近寫**需要用到將一些漢字的首字母作為列舉型的要求,網上看到了這個方法,在excel vb指令碼中使用,在這記錄下:

下面是乙個vba自定義函式,按alt+f11,插入模組,在右面視窗中貼上下面**。

若b10內容為 中國航天6號a,則在某空白格中輸入:=hztopy(b10) 即可

function hztopy(hzpy as string) as string

dim hzstring as string, pystring as string

dim hzpysum as integer, hzi as integer, hzpyhex as integer

hzstring = trim(hzpy)

hzpysum = len(trim(hzstring))

pystring = ""

for hzi = 1 to hzpysum

hzpyhex = "&h" + hex(asc(mid(hzstring, hzi, 1)))

select case hzpyhex

case &hb0a1 to &hb0c4: pystring = pystring + "a"

case &hb0c5 to &hb2c0: pystring = pystring + "b"

case &hb2c1 to &hb4ed: pystring = pystring + "c"

case &hb4ee to &hb6e9: pystring = pystring + "d"

case &hb6ea to &hb7a1: pystring = pystring + "e"

case &hb7a2 to &hb8c0: pystring = pystring + "f"

case &hb8c1 to &hb9fd: pystring = pystring + "g"

case &hb9fe to &hbbf6: pystring = pystring + "h"

case &hbbf7 to &hbfa5: pystring = pystring + "j"

case &hbfa6 to &hc0ab: pystring = pystring + "k"

case &hc0ac to &hc2e7: pystring = pystring + "l"

case &hc2e8 to &hc4c2: pystring = pystring + "m"

case &hc4c3 to &hc5b5: pystring = pystring + "n"

case &hc5b6 to &hc5bd: pystring = pystring + "o"

case &hc5be to &hc6d9: pystring = pystring + "p"

case &hc6da to &hc8ba: pystring = pystring + "q"

case &hc8bb to &hc8f5: pystring = pystring + "r"

case &hc8f6 to &hcbf9: pystring = pystring + "s"

case &hcbfa to &hcdd9: pystring = pystring + "t"

case &hedc5: pystring = pystring + "t"

case &hcdda to &hcef3: pystring = pystring + "w"

case &hcef4 to &hd1b8: pystring = pystring + "x"

case &hd1b9 to &hd4d0: pystring = pystring + "y"

case &hd4d1 to &hd7f9: pystring = pystring + "z"

case else

pystring = pystring + mid(hzstring, hzi, 1)

end select

next

hztopy = pystring

end function

C 取得漢字的拼音的首字母。

今天在yyf9989 的 blog 上看到一篇 c 計算漢語拼音碼 看了裡面的 覺得是比較繁瑣。它主要是檢索輸入的漢字在陣列中的位置,然後返回第乙個字母。於是就想起來了,可以利用漢字在計算機裡面的編碼來的到漢字的首拼音,查詢了一些資料,通過以下的方法成功的得到了解決。就放在這裡,請朋友們參考。sta...

漢字轉拼音首字母

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...