设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

12下一页
返回列表 发新帖
查看: 7404|回复: 17
打印 上一主题 下一主题

[其它] [求助]怎样自动取出汉字的拼音首字母呢?

[复制链接]
跳转到指定楼层
1#
发表于 2004-12-2 01:41:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如题!谢谢指点!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享分享 分享淘帖 订阅订阅
2#
发表于 2004-12-2 02:39:00 | 只看该作者
用left即可
3#
 楼主| 发表于 2004-12-2 03:20:00 | 只看该作者
谢谢楼上!left(string,length)不是取出字符串string左边的指定length个字符吗?我的意思是这样的:现有一个变量里面的内容是汉字如: "汉字"我应该怎样让系统自动根据 "汉字" 把 "hz" 对应取出来呢?
4#
发表于 2004-12-2 03:32:00 | 只看该作者
 left(变量名,1),不知可不可以解决您的问题,请指教谢谢!!
5#
发表于 2004-12-2 16:22:00 | 只看该作者
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





6#
 楼主| 发表于 2004-12-2 23:21:00 | 只看该作者
谢谢楼上!后来我又找了找。找到下面的代码,好像也可以的     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)



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

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

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-6 17:20 , Processed in 0.083404 second(s), 33 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表