Office中国论坛/Access中国论坛

标题: [求助]怎样自动取出汉字的拼音首字母呢? [打印本页]

作者: kq_sun    时间: 2004-12-2 01:41
标题: [求助]怎样自动取出汉字的拼音首字母呢?
如题!谢谢指点!
作者: zyp    时间: 2004-12-2 02:39
用left即可
作者: kq_sun    时间: 2004-12-2 03:20
谢谢楼上!left(string,length)不是取出字符串string左边的指定length个字符吗?我的意思是这样的:现有一个变量里面的内容是汉字如: "汉字"我应该怎样让系统自动根据 "汉字" 把 "hz" 对应取出来呢?
作者: zhanguoru    时间: 2004-12-2 03:32
 left(变量名,1),不知可不可以解决您的问题,请指教谢谢!!
作者: Trynew    时间: 2004-12-2 16:22
HZPY(String):返回汉字拼音首字母函数:Function HZPY(hzstr As String) As String

Dim p0 As String, C As String, STR As String

Dim i As Integer, j As Integer

p0 = "吖八嚓咑妸发旮铪讥讥咔垃呣拿讴趴七呥仨他哇哇哇夕丫匝咗"

For i = 1 To Len(hzstr)

    C = "z"

    STR = Mid(hzstr, i, 1)

    If Asc(STR) > 0 Then

        C = STR

    Else

        For j = 1 To 26

            If Mid(p0, j, 1) > STR Then

                C = Chr(95 + j)

                Exit For

            End If

        Next

    End If

    HZPY= HZPY+ C

Next

End Function






作者: kq_sun    时间: 2004-12-2 23:21
谢谢楼上!后来我又找了找。找到下面的代码,好像也可以的     function getpychar(char)

     tmp=65536+asc(char)

     if(tmp>=45217 and tmp<=45252) then

     getpychar= "A"

     elseif(tmp>=45253 and tmp<=45760) then

     getpychar= "B"

     elseif(tmp>=45761 and tmp<=46317) then

     getpychar= "C"

     elseif(tmp>=46318 and tmp<=46825) then

     getpychar= "D"

     elseif(tmp>=46826 and tmp<=47009) then

     getpychar= "E"

     elseif(tmp>=47010 and tmp<=47296) then

     getpychar= "F"

     elseif(tmp>=47297 and tmp<=47613) then

     getpychar= "G"

     elseif(tmp>=47614 and tmp<=48118) then

     getpychar= "H"

     elseif(tmp>=48119 and tmp<=49061) then

     getpychar= "J"

     elseif(tmp>=49062 and tmp<=49323) then

     getpychar= "K"

     elseif(tmp>=49324 and tmp<=49895) then

     getpychar= "L"

     elseif(tmp>=49896 and tmp<=50370) then

     getpychar= "M"

     elseif(tmp>=50371 and tmp<=50613) then

     getpychar= "N"

     elseif(tmp>=50614 and tmp<=50621) then

     getpychar= "O"

     elseif(tmp>=50622 and tmp<=50905) then

     getpychar= ""

     elseif(tmp>=50906 and tmp<=51386) then

     getpychar= "Q"

     elseif(tmp>=51387 and tmp<=51445) then

     getpychar= "R"

     elseif(tmp>=51446 and tmp<=52217) then

     getpychar= "S"

     elseif(tmp>=52218 and tmp<=52697) then

     getpychar= "T"

     elseif(tmp>=52698 and tmp<=52979) then

     getpychar= "W"

     elseif(tmp>=52980 and tmp<=53640) then

     getpychar= "X"

     elseif(tmp>=53689 and tmp<=54480) then

     getpychar= "Y"

     elseif(tmp>=54481 and tmp<=62289) then

     getpychar= "Z"

     else '如果不是中文,则不处理

     getpychar=char

     end if

     end function

     

     function getpy(str)

     for i=1 to len(str)

     getpy=getpy&getpychar(mid(str,i,1))

     next

     end function

     d="只查"

     msgbox getpy(d)




作者: acc_user    时间: 2004-12-3 05:59
谢谢5、6楼的,我正要用
作者: hgt    时间: 2004-12-3 16:55
5楼的函数非常好,6楼的函数有些字不能转。
作者: zyp    时间: 2004-12-3 17:05
Trynew版主能不能分析一下此函數的原理,因為在繁體中無法通過,"吖八嚓咑妸发旮铪讥讥咔垃呣拿讴趴七呥仨他哇哇哇夕丫匝咗"到了繁體中全是亂碼了.謝謝!
作者: Trynew    时间: 2004-12-5 17:10
此函數的原理:汉字是根据拼音来排序的,找出所有的汉字(找出所有的汉字的方法可以把Chr(-1)到Chr(-32500)加到一个表中,),进行排序,再找出每个字母的第一个汉字,组成字符串,i、u、v没有拼音,就用后面字母代替,如“讥讥”,“哇哇哇”。把要取拼音首字母的汉字跟字符串比较,落在哪个区间,就是哪个首字母。

[此贴子已经被作者于2004-12-7 8:12:59编辑过]


作者: zyp    时间: 2004-12-5 21:31
多謝Trynew版主的無私奉獻

我試了一下,asc(-1)返回的是數字啊,沒有中文!!!

???[em17][em17][em17][em17][em17][em17][em17]

[此贴子已经被作者于2004-12-5 17:18:06编辑过]


作者: zyp    时间: 2004-12-6 01:18
???
作者: Trynew    时间: 2004-12-7 16:15
写错了,asc(-1)返回的是數字,Chr(-1)返回的是中文
作者: zyp    时间: 2004-12-8 15:57
謝謝樓上不知是我系統的問題還是其它問題,用Chr提取的大部分為"?",而且好像不是按拼音首字排序的.我得換一臺電腦試試
作者: fb008    时间: 2004-12-16 14:04
5楼的好
作者: zhanguoru    时间: 2005-2-21 21:47
收藏
作者: ningshen    时间: 2006-3-26 20:53
不错呀
作者: fan0217    时间: 2006-3-26 21:19
参阅:http://www.office-cn.net/forum.php?mod=viewthread&tid=36059&replyID=&skin=1
作者: tz-chf    时间: 2006-3-27 01:55
6楼的好象和northwind的一样
作者: wellcome_gx    时间: 2009-11-9 06:18
正在找这方面的东西, 感谢




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3