提取中文字串的拼音首字母

提取中文字串的拼音首字母

来源:excel格子社区

一个自定义函数,可提取中文字串中每个字符的拼音首字母,忽略字串中的英文字母和标点,阿拉伯数字,空格等。

附件中有使用范例。

已发现的缺点:不能识别多音字,比如“单”有"shan、dan"两种读音,其只能识别一种;

到底能识别多少中文字,我也不清楚。

Function HYPY(myStr As String) As String

Dim L As Integer, i As Integer

Dim GetPY As String, N As String

On Error Resume Next

myStr = StrConv(myStr, vbNarrow)

L = Len(myStr)

For i = 1 To L

If Asc(Mid(myStr, i, 1)) > 0 Or Err.Number = 1004 Then N = ""

N =

Application.WorksheetFunction.VLookup(Mid(mySt r, i, 1), _

[{"吖","A";"八","B";"嚓","C";"咑","D";"鵽","E";"发","F";"猤","G";"铪","H";"夻","J";"咔","K";"垃","L";"嘸","M";"旀","N";"噢","O";"妑","P";"七","Q";"囕","R";"仨","S";"他","T";"屲","W";"夕","X";"丫","Y";"帀","Z"}], 2) GetPY = GetPY & N

Next i

HYPY = GetPY

End Function

相关文档
最新文档