`
阅: 2387 | 回: 0
发表于2015/10/27 12:44:56 楼主 
头像 等级:初学者
积分:0
财富值:0.0
身份:普通用户
提取中文字串的拼音首字母

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

我的个性签名

快速回复

目前不允许游客发表,请 登录 注册 后再发贴。