其一,只对汉字取拼音首字母,使用Like运算符进行限定就好了。
其二,使用工作表函数LOOKUP从对照表中查取汉字的对应字母,无须声明"Option Compare Text"
- Public Function PY_ZY$(str As String, Optional Ignore As Boolean = False)
- Dim i&, s$
- If Not IsArray(pyarr) Then pyarr = [{"吖","a";"八","b";"攃","c";"咑","d";"妸","e";"发","f";"旮","g";"哈","h";"丌","j";"咔","k";"垃","l";"妈","m";"拏","n";"噢","o";"帊","p";"七","q";"冄","r";"仨","s";"他","t";"屲","w";"夕","x";"丫","y";"帀","z"}]
- If Ignore Then str = LCase(str)
- str = Replace(str, " ", "")
- For i = 1 To Len(str)
- s = Mid(str, i, 1)
- If s Like "[一-龥]" Then
- If s = "长" Then s = "c" Else s = Application.Lookup(s, pyarr)
- If Ignore Then s = LCase(s)
- Mid(str, i, 1) = s
- End If
- Next
- PY_ZY = str
- End Function
复制代码 |