当前位置:首页 > Excel函数教程 > 提取中文字串的拼音首字母

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

来源:Excel中文网 作者:Excelcn 发布时间:2006-03-29

一个自定义函数,可提取中文字串中每个字符的拼音首字母,忽略字串中的英文字母和标点,阿拉伯数字,空格等。
附件中有使用范例。
已发现的缺点:不能识别多音字,比如 “单”有"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(myStr, 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
| 网站地图 All Rights Reserved. Powered by Excel中文网