Access交流中心

北京 | 上海 | 天津 | 重庆 | 广州 | 深圳 | 珠海 | 汕头 | 佛山 | 中山 | 东莞 | 南京 | 苏州 | 无锡 | 常州 | 南通 | 扬州 | 徐州 | 杭州 | 温州 | 宁波 | 台州 | 福州 | 厦门 | 泉州 | 龙岩 | 合肥 | 芜湖 | 成都 | 遂宁 | 长沙 | 株洲 | 湘潭 | 武汉 | 南昌 | 济南 | 青岛 | 烟台 | 潍坊 | 淄博 | 济宁 | 太原 | 郑州 | 石家庄 | 保定 | 唐山 | 西安 | 大连 | 沈阳 | 长春 | 昆明 | 兰州 | 哈尔滨 | 佳木斯 | 南宁 | 桂林 | 海口 | 贵阳 | 西宁 | 乌鲁木齐 | 包头 |

有没有通过汉字确定该字拼音首字母的函数?

贺德才  发表于:2009-06-15 10:43:07  
复制

我在网上看到一个通过汉字确定该字汉语拼音的函数,很好用。我在使用过程中有这样一个需求,想通过汉字确定该字的拼音首字母,如果是几个字的话,就确定这几个字的首字母。比如,我输入“贺”,另一个文本框会出现“h”;如果我输入“贺德才”,另一个文本框内就出现“hdc”。这个函数该怎么写?谢谢各位高手指点。

 

Top
点燃一支烟 发表于:2009-06-15 11:39:18

Public Function PY(Tstr As String) As String
Dim a, N, i As Long
Dim b, d, PinYin As String

a = Len(Tstr)
For N = 1 To a
    b = Mid(Tstr, N, 1)
'    Debug.Print B
    i = Asc(b)

'I = Asc(Tstr)


If i >= Asc("啊") And i < Asc("芭") Then PinYin = "a"

If i >= Asc("芭") And i < Asc("擦") Then PinYin = "b"

If i >= Asc("擦") And i < Asc("搭") Then PinYin = "c"

If i >= Asc("搭") And i < Asc("蛾") Then PinYin = "d"

If i >= Asc("蛾") And i < Asc("发") Then PinYin = "e"

If i >= Asc("发") And i < Asc("噶") Then PinYin = "f"

If i >= Asc("噶") And i < Asc("哈") Then PinYin = "g"

If i >= Asc("哈") And i < Asc("击") Then PinYin = "h"

If i >= Asc("击") And i < Asc("喀") Then PinYin = "j"

If i >= Asc("喀") And i < Asc("垃") Then PinYin = "k"

If i >= Asc("垃") And i < Asc("妈") Then PinYin = "l"

If i >= Asc("妈") And i < Asc("拿") Then PinYin = "m"

If i >= Asc("拿") And i < Asc("哦") Then PinYin = "n"

If i >= Asc("哦") And i < Asc("啪") Then PinYin = "o"

If i >= Asc("啪") And i < Asc("欺") Then PinYin = "p"

If i >= Asc("欺") And i < Asc("然") Then PinYin = "q"

If i >= Asc("然") And i < Asc("撒") Then PinYin = "r"

If i >= Asc("撒") And i < Asc("塌") Then PinYin = "s"

If i >= Asc("塌") And i < Asc("挖") Then PinYin = "t"

If i >= Asc("挖") And i < Asc("昔") Then PinYin = "w"

If i >= Asc("昔") And i < Asc("压") Then PinYin = "x"

If i >= Asc("压") And i < Asc("匝") Then PinYin = "y"

If i >= Asc("匝") And i <= Asc("座") Then PinYin = "z"

d = d & PinYin
Next N
'Debug.Print D
PY = d
End Function



点燃一支烟 发表于:2009-06-15 11:50:10
点击下载此附件见示例的窗体,在左边文本框输入汉字,右边文本框显示首拼小写,在左边的更新后事件中响应

豆豆 发表于:2009-06-15 14:41:03

2楼的附件,在输入“晁建安”时

只能得到ja2个字母。

请看这个附件

点击下载此附件

贺德才 发表于:2009-06-15 15:14:06

感谢dengshaobin先生的提示,很好的。但有一个小问题,怪我说的不准确,我要的其实是每个汉字的声母,比如“贺”声母是“h”,陈、郑应该是“ch”、“zh”。就是这个意思。



点燃一支烟 发表于:2009-06-15 16:53:42
总记录:5篇  页次:1/1 9 1 :