excel中如何实现提取汉字的拼音首字母

时间:2022-05-22 08:02:15
http://zhidao.baidu.com/question/104836508.html

汉字中还包含英文字母或数字,英文或数字部分也要返回。
比如:中国航天6号a
返回应为:ZGHT6Ha

下面是一个VBA自定义函数,按ALT+F11,插入模块,在右面窗口中粘贴下面代码。
若A1内容为 中国航天6号a,则在某空白格中输入:=hztopy(A1) 即可

Function hztopy(hzpy As String) As String
  Dim hzstring As String, pystring As String
  Dim hzpysum As Integer, hzi As Integer, hzpyhex As Integer
  hzstring = Trim(hzpy)
  hzpysum = Len(Trim(hzstring))
  pystring = ""
  For hzi = 1 To hzpysum
    hzpyhex = "&H" + Hex(Asc(Mid(hzstring, hzi, 1)))
    Select Case hzpyhex
      Case &HB0A1 To &HB0C4: pystring = pystring + "a"
      Case &HB0C5 To &HB2C0: pystring = pystring + "b"
      Case &HB2C1 To &HB4ED: pystring = pystring + "c"
      Case &HB4EE To &HB6E9: pystring = pystring + "d"
      Case &HB6EA To &HB7A1: pystring = pystring + "e"
      Case &HB7A2 To &HB8C0: pystring = pystring + "f"
      Case &HB8C1 To &HB9FD: pystring = pystring + "g"
      Case &HB9FE To &HBBF6: pystring = pystring + "h"
      Case &HBBF7 To &HBFA5: pystring = pystring + "j"
      Case &HBFA6 To &HC0AB: pystring = pystring + "k"
      Case &HC0AC To &HC2E7: pystring = pystring + "l"
      Case &HC2E8 To &HC4C2: pystring = pystring + "m"
      Case &HC4C3 To &HC5B5: pystring = pystring + "n"
      Case &HC5B6 To &HC5BD: pystring = pystring + "o"
      Case &HC5BE To &HC6D9: pystring = pystring + "p"
      Case &HC6DA To &HC8BA: pystring = pystring + "q"
      Case &HC8BB To &HC8F5: pystring = pystring + "r"
      Case &HC8F6 To &HCBF9: pystring = pystring + "s"
      Case &HCBFA To &HCDD9: pystring = pystring + "t"
      Case &HEDC5: pystring = pystring + "t"
      Case &HCDDA To &HCEF3: pystring = pystring + "w"
      Case &HCEF4 To &HD1B8: pystring = pystring + "x"
      Case &HD1B9 To &HD4D0: pystring = pystring + "y"
      Case &HD4D1 To &HD7F9: pystring = pystring + "z"
      Case Else
        pystring = pystring + Mid(hzstring, hzi, 1)
    End Select
  Next
  hztopy = pystring
End Function

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script> 阅读(3313) | 评论(0) | 转发(0) | 0

上一篇:企业自动化运维

下一篇:high_memory 物理地址最高值 内存 大于 1G

相关热门文章 给主人留下些什么吧!~~ 评论热议