摘抄Excel和FoxPro獲取漢字拼音首字母縮寫的方法.

qdrzq發表於2015-01-26
摘抄Excel和FoxPro獲取漢字拼音首字母縮寫的方法.

(1)Excel

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

(2)FoxPro
case asc(s)>=asc('啊').and.asc(s)             p_=p_+'a'
         case asc(s)>=asc('芭').and.asc(s)             p_=p_+'b'
         case asc(s)>=asc('擦').and.asc(s)             p_=p_+'c'
         case asc(s)>=asc('搭').and.asc(s)             p_=p_+'d'
         case asc(s)>=asc('蛾').and.asc(s)             p_=p_+'e'
         case asc(s)>=asc('發').and.asc(s)             p_=p_+'f'
         case asc(s)>=asc('噶').and.asc(s)             p_=p_+'g'
         case asc(s)>=asc('哈').and.asc(s)             p_=p_+'h'
         case asc(s)>=asc('擊').and.asc(s)             p_=p_+'j'
         case asc(s)>=asc('喀').and.asc(s)             p_=p_+'k'
         case asc(s)>=asc('垃').and.asc(s)             p_=p_+'l'
         case asc(s)>=asc('媽').and.asc(s)             p_=p_+'m'
         case asc(s)>=asc('拿').and.asc(s)             p_=p_+'n'
         case asc(s)>=asc('哦').and.asc(s)             p_=p_+'o'
         case asc(s)>=asc('啪').and.asc(s)             p_=p_+'p'
         case asc(s)>=asc('期').and.asc(s)             p_=p_+'q'
         case asc(s)>=asc('然').and.asc(s)             p_=p_+'r'
         case asc(s)>=asc('撒').and.asc(s)             p_=p_+'s'
         case asc(s)>=asc('塌').and.asc(s)             p_=p_+'t'
         case asc(s)>=asc('挖').and.asc(s)             p_=p_+'w'
         case asc(s)>=asc('昔').and.asc(s)             p_=p_+'x'
         case asc(s)>=asc('壓').and.asc(s)             p_=p_+'y'
         case asc(s)>=asc('匝').and.s not='馨'.and.s not='煒'.and.s not='剴'.and.s not='翩'.and.s not='懿'
            p_=p_+'z'
說明一下,兩種方法對於國標區位碼16-55區(以音序排列,上半區)適用.而對於56-87區(以部首排列,下半區)的漢字,則不適用.
這也正是方法中出現了若干or條件,將不滿足區位碼上半區音序排列的分界字元原則的漢字予以單獨羅列的原因.其實如果知道了區位碼的編碼原則,這種or是羅列不盡的.
理想的獲取方法,還是需要使用資料庫的排序規則(MS SQL Server)或者字符集排序特性(Oracle).

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29512902/viewspace-1416001/,如需轉載,請註明出處,否則將追究法律責任。

相關文章