以下是引用zdlah在2004-10-23 2:34:00的发言:
如“中国”,能否用一个函数,自动将它的拼音缩写转换为“ZG”
ySw8UH4N.rar
(8.7 KB, 下载次数: 429)
shangyu 版主的函数功夫确实好! 拼音简写的函数使用令人耳目一新,精神一振![em17]
这是一个由Jack.zhou附上的共享拼音代码(见http://club.excelhome.net/viewthread.php?tid=55585)
我以为这个也较具有代表性,并希望能得到更多推广与应用。
遂重新修饰了一个代码,用select case ……end select语句代替了IF ……end if ,使之运算速度更为加快,结构更趋合理。
此文件可另存加载宏,以备随时调动更好。(函数名为getpy())
以下为自定义函数代码供参考:
Function Getpychar(char)
Dim Tmp As Long
Tmp = 65536 + Asc(char)
Select Case Tmp
Case 45217 To 45252
Getpychar = "A"
Case 45253 To 45760
Getpychar = "B"
Case 45761 To 46317
Getpychar = "C"
Case 46318 To 46825
Getpychar = "D"
Case 46826 To 47009
Getpychar = "E"
Case 47010 To 47296
Getpychar = "F"
Case 47297 To 47613
Getpychar = "G"
Case 47614 To 48118
Getpychar = "H"
Case 48119 To 49061
Getpychar = "J"
Case 49062 To 49323
Getpychar = "K"
Case 49324 To 49895
Getpychar = "L"
Case 49896 To 50370
Getpychar = "M"
Case 50371 To 50613
Getpychar = "N"
Case 50614 To 50621
Getpychar = "O"
Case 50622 To 50905
Getpychar = "P"
Case 50906 To 51386
Getpychar = "Q"
Case 51387 To 51445
Getpychar = "R"
Case 51446 To 52217
Getpychar = "S"
Case 52218 To 52697
Getpychar = "T"
Case 52698 To 52979
Getpychar = "W"
Case 52980 To 53640
Getpychar = "X"
Case 53689 To 54480
Getpychar = "Y"
Case 54481 To 62289
Getpychar = "Z"
Case Else
'如果不是中文,则不处理
Getpychar = char
End Select
End Function
'*********************************
Function Getpy(str)
For i = 1 To Len(str)
Getpy = Getpy & Getpychar(Mid(str, i, 1))
Next
End Function |