'*************************************************************************
'**函 数 名:gGetPinYin
'**输 入:ByVal intHanZiAsc(Integer) -汉字的ASCII码,用ASC函数取得
'**输 出:(String) -一个拼音字符串
'**功能描述:输入一个汉字,输出一个拼音
'**全局变量:
'**调用模块:
'**作 者:wild
'**日 期:2004-10-06
'**修 改 人:
'**日 期:
'**版 本:V1.1.78
'*************************************************************************
Public Function gGetPinYin(ByVal strHanZi As String) As String
Dim objPinYinDic As Variant
Set objPinYinDic = CreateObject("Scripting.Dictionary")
objPinYinDic.Add "a", -20319
objPinYinDic.Add "ai", -20317
objPinYinDic.Add "an", -20304
objPinYinDic.Add "ang", -20295
objPinYinDic.Add "ao", -20292
objPinYinDic.Add "ba", -20283
objPinYinDic.Add "bai", -20265
objPinYinDic.Add "ban", -20257
objPinYinDic.Add "bang", -20242
objPinYinDic.Add "bao", -20230
objPinYinDic.Add "bei", -20051
objPinYinDic.Add "ben", -20036
objPinYinDic.Add "beng", -20032
objPinYinDic.Add "bi", -20026
objPinYinDic.Add "bian", -20002
objPinYinDic.Add "biao", -19990
objPinYinDic.Add "bie", -19986
objPinYinDic.Add "bin", -19982
objPinYinDic.Add "bing", -19976
objPinYinDic.Add "bo", -19805
objPinYinDic.Add "bu", -19784
objPinYinDic.Add "ca", -19775
objPinYinDic.Add "cai", -19774
objPinYinDic.Add "can", -19763
objPinYinDic.Add "cang", -19756
objPinYinDic.Add "cao", -19751
objPinYinDic.Add "ce", -19746
objPinYinDic.Add "ceng", -19741
objPinYinDic.Add "cha", -19739
objPinYinDic.Add "chai", -19728
objPinYinDic.Add "chan", -19725
objPinYinDic.Add "chang", -19715
objPinYinDic.Add "chao", -19540
objPinYinDic.Add "che", -19531
objPinYinDic.Add "chen", -19525
objPinYinDic.Add "cheng", -19515
objPinYinDic.Add "chi", -19500
objPinYinDic.Add "chong", -19484
objPinYinDic.Add "chou", -19479
objPinYinDic.Add "chu", -19467
objPinYinDic.Add "chuai", -19289
objPinYinDic.Add "chuan", -19288
objPinYinDic.Add "chuang", -19281
objPinYinDic.Add "chui", -19275
objPinYinDic.Add "chun", -19270
objPinYinDic.Add "chuo", -19263
objPinYinDic.Add "ci", -19261
objPinYinDic.Add "cong", -19249
objPinYinDic.Add "cou", -19243
objPinYinDic.Add "cu", -19242
objPinYinDic.Add "cuan", -19238
objPinYinDic.Add "cui", -19235
objPinYinDic.Add "cun", -19227
objPinYinDic.Add "cuo", -19224
objPinYinDic.Add "da", -19218
objPinYinDic.Add "dai", -19212
objPinYinDic.Add "dan", -19038
objPinYinDic.Add "dang", -19023
objPinYinDic.Add "dao", -19018
objPinYinDic.Add "de", -19006
objPinYinDic.Add "deng", -19003
objPinYinDic.Add "di", -18996
objPinYinDic.Add "dian", -18977
objPinYinDic.Add "diao", -18961
objPinYinDic.Add "die", -18952
objPinYinDic.Add "ding", -18783
objPinYinDic.Add "diu", -18774
objPinYinDic.Add "dong", -18773
objPinYinDic.Add "dou", -18763
objPinYinDic.Add "du", -18756
objPinYinDic.Add "duan", -18741
objPinYinDic.Add "dui", -18735
objPinYinDic.Add "dun", -18731
objPinYinDic.Add "duo", -18722
objPinYinDic.Add "e", -18710
objPinYinDic.Add "en", -18697
objPinYinDic.Add "er", -18696
objPinYinDic.Add "fa", -18526
objPinYinDic.Add "fan", -18518
objPinYinDic.Add "fang", -18501
objPinYinDic.Add "fei", -18490
objPinYinDic.Add "fen", -18478
objPinYinDic.Add "feng", -18463
objPinYinDic.Add "fo", -18448
objPinYinDic.Add "fou", -18447
objPinYinDic.Add "fu", -18446
objPinYinDic.Add "ga", -18239
objPinYinDic.Add "gai", -18237
objPinYinDic.Add "gan", -18231
objPinYinDic.Add "gang", -18220
objPinYinDic.Add "gao", -18211
objPinYinDic.Add "ge", -18201
objPinYinDic.Add "gei", -18184
objPinYinDic.Add "gen", -18183
objPinYinDic.Add "geng", -18181
objPinYinDic.Add "gong", -18012
objPinYinDic.Add "gou", -17997
objPinYinDic.Add "gu", -17988
objPinYinDic.Add "gua", -17970
objPinYinDic.Add "guai", -17964
objPinYinDic.Add "guan", -17961
objPinYinDic.Add "guang", -17950
objPinYinDic.Add "gui", -17947
objPinYinDic.Add "gun", -17931
objPinYinDic.Add "guo", -17928
objPinYinDic.Add "ha", -17922
objPinYinDic.Add "hai", -17759
objPinYinDic.Add "han", -17752
objPinYinDic.Add "hang", -17733
objPinYinDic.Add "hao", -17730
objPinYinDic.Add "he", -17721
objPinYinDic.Add "hei", -17703
objPinYinDic.Add "hen", -17701
objPinYinDic.Add "heng", -17697
objPinYinDic.Add "hong", -17692
objPinYinDic.Add "hou", -17683
objPinYinDic.Add "hu", -17676
objPinYinDic.Add "hua", -17496
objPinYinDic.Add "huai", -17487
objPinYinDic.Add "huan", -17482
objPinYinDic.Add "huang", -17468
objPinYinDic.Add "hui", -17454
objPinYinDic.Add "hun", -17433
objPinYinDic.Add "huo", -17427
objPinYinDic.Add "ji", -17417
objPinYinDic.Add "jia", -17202
objPinYinDic.Add "jian", -17185
objPinYinDic.Add "jiang", -16983
objPinYinDic.Add "jiao", -16970
objPinYinDic.Add "jie", -16942
objPinYinDic.Add "jin", -16915
objPinYinDic.Add "jing", -16733
objPinYinDic.Add "jiong", -16708
objPinYinDic.Add "jiu", -16706
objPinYinDic.Add "ju", -16689
objPinYinDic.Add "juan", -16664
objPinYinDic.Add "jue", -16657
objPinYinDic.Add "jun", -16647
objPinYinDic.Add "ka", -16474
objPinYinDic.Add "kai", -16470
objPinYinDic.Add "kan", -16465
objPinYinDic.Add "kang", -16459
objPinYinDic.Add "kao", -16452
objPinYinDic.Add "ke", -16448
objPinYinDic.Add "ken", -16433
objPinYinDic.Add "keng", -16429
objPinYinDic.Add "kong", -16427
objPinYinDic.Add "kou", -16423
objPinYinDic.Add "ku", -16419
objPinYinDic.Add "kua", -16412
objPinYinDic.Add "kuai", -16407
objPinYinDic.Add "kuan", -16403
objPinYinDic.Add "kuang", -16401
objPinYinDic.Add "kui", -16393
objPinYinDic.Add "kun", -16220
objPinYinDic.Add "kuo", -16216
objPinYinDic.Add "la", -16212
objPinYinDic.Add "lai", -16205
objPinYinDic.Add "lan", -16202
objPinYinDic.Add "lang", -16187
objPinYinDic.Add "lao", -16180
objPinYinDic.Add "le", -16171
objPinYinDic.Add "lei", -16169
objPinYinDic.Add "leng", -16158
objPinYinDic.Add "li", -16155
objPinYinDic.Add "lia", -15959
objPinYinDic.Add "lian", -15958
objPinYinDic.Add "liang", -15944
objPinYinDic.Add "liao", -15933
objPinYinDic.Add "lie", -15920
objPinYinDic.Add "lin", -15915
objPinYinDic.Add "ling", -15903
objPinYinDic.Add "liu", -15889
objPinYinDic.Add "long", -15878
objPinYinDic.Add "lou", -15707
objPinYinDic.Add "lu", -15701
objPinYinDic.Add "lv", -15681
objPinYinDic.Add "luan", -15667
objPinYinDic.Add "lue", -15661
objPinYinDic.Add "lun", -15659
objPinYinDic.Add "luo", -15652
objPinYinDic.Add "ma", -15640
objPinYinDic.Add "mai", -15631
objPinYinDic.Add "man", -15625
objPinYinDic.Add "mang", -15454
objPinYinDic.Add "mao", -15448
objPinYinDic.Add "me", -15436
objPinYinDic.Add "mei", -15435
objPinYinDic.Add "men", -15419
objPinYinDic.Add "meng", -15416
objPinYinDic.Add "mi", -15408
objPinYinDic.Add "mian", -15394
objPinYinDic.Add "miao", -15385
objPinYinDic.Add "mie", -15377
objPinYinDic.Add "min", -15375
objPinYinDic.Add "ming", -15369
objPinYinDic.Add "miu", -15363
objPinYinDic.Add "mo", -15362
objPinYinDic.Add "mou", -15183
objPinYinDic.Add "mu", -15180
objPinYinDic.Add "na", -15165
objPinYinDic.Add "nai", -15158
objPinYinDic.Add "nan", -15153
objPinYinDic.Add "nang", -15150
objPinYinDic.Add "nao", -15149
objPinYinDic.Add "ne", -15144
objPinYinDic.Add "nei", -15143
objPinYinDic.Add "nen", -15141
objPinYinDic.Add "neng", -15140
objPinYinDic.Add "ni", -15139
objPinYinDic.Add "nian", -15128
objPinYinDic.Add "niang", -15121
objPinYinDic.Add "niao", -15119
objPinYinDic.Add "nie", -15117
objPinYinDic.Add "nin", -15110
objPinYinDic.Add "ning", -15109
objPinYinDic.Add "niu", -14941
objPinYinDic.Add "nong", -14937
objPinYinDic.Add "nu", -14933
objPinYinDic.Add "nv", -14930
objPinYinDic.Add "nuan", -14929
objPinYinDic.Add "nue", -14928
objPinYinDic.Add "nuo", -14926
objPinYinDic.Add "o", -14922
objPinYinDic.Add "ou", -14921
objPinYinDic.Add "pa", -14914
objPinYinDic.Add "pai", -14908
objPinYinDic.Add "pan", -14902
objPinYinDic.Add "pang", -14894
objPinYinDic.Add "pao", -14889
objPinYinDic.Add "pei", -14882
objPinYinDic.Add "pen", -14873
objPinYinDic.Add "peng", -14871
objPinYinDic.Add "pi", -14857
objPinYinDic.Add "pian", -14678
objPinYinDic.Add "piao", -14674
objPinYinDic.Add "pie", -14670
objPinYinDic.Add "pin", -14668
objPinYinDic.Add "ping", -14663
objPinYinDic.Add "po", -14654
objPinYinDic.Add "pu", -14645
objPinYinDic.Add "qi", -14630
objPinYinDic.Add "qia", -14594
objPinYinDic.Add "qian", -14429
objPinYinDic.Add "qiang", -14407
objPinYinDic.Add "qiao", -14399
objPinYinDic.Add "qie", -14384
objPinYinDic.Add "qin", -14379
objPinYinDic.Add "qing", -14368
objPinYinDic.Add "qiong", -14355
objPinYinDic.Add "qiu", -14353
objPinYinDic.Add "qu", -14345
objPinYinDic.Add "quan", -14170
objPinYinDic.Add "que", -14159
objPinYinDic.Add "qun", -14151
objPinYinDic.Add "ran", -14149
objPinYinDic.Add "rang", -14145
objPinYinDic.Add "rao", -14140
objPinYinDic.Add "re", -14137
objPinYinDic.Add "ren", -14135
objPinYinDic.Add "reng", -14125
objPinYinDic.Add "ri", -14123
objPinYinDic.Add "rong", -14122
objPinYinDic.Add "rou", -14112
objPinYinDic.Add "ru", -14109
objPinYinDic.Add "ruan", -14099
objPinYinDic.Add "rui", -14097
objPinYinDic.Add "run", -14094
objPinYinDic.Add "ruo", -14092
objPinYinDic.Add "sa", -14090
objPinYinDic.Add "sai", -14087
objPinYinDic.Add "san", -14083
objPinYinDic.Add "sang", -13917
objPinYinDic.Add "sao", -13914
objPinYinDic.Add "se", -13910
objPinYinDic.Add "sen", -13907
objPinYinDic.Add "seng", -13906
objPinYinDic.Add "sha", -13905
objPinYinDic.Add "shai", -13896
objPinYinDic.Add "shan", -13894
objPinYinDic.Add "shang", -13878
objPinYinDic.Add "shao", -13870
objPinYinDic.Add "she", -13859
objPinYinDic.Add "shen", -13847
objPinYinDic.Add "sheng", -13831
objPinYinDic.Add "shi", -13658
objPinYinDic.Add "shou", -13611
objPinYinDic.Add "shu", -13601
objPinYinDic.Add "shua", -13406
objPinYinDic.Add "shuai", -13404
objPinYinDic.Add "shuan", -13400
objPinYinDic.Add "shuang", -13398
objPinYinDic.Add "shui", -13395
objPinYinDic.Add "shun", -13391
objPinYinDic.Add "shuo", -13387
objPinYinDic.Add "si", -13383
objPinYinDic.Add "song", -13367
objPinYinDic.Add "sou", -13359
objPinYinDic.Add "su", -13356
objPinYinDic.Add "suan", -13343
objPinYinDic.Add "sui", -13340
objPinYinDic.Add "sun", -13329
objPinYinDic.Add "suo", -13326
objPinYinDic.Add "ta", -13318
objPinYinDic.Add "tai", -13147
objPinYinDic.Add "tan", -13138
objPinYinDic.Add "tang", -13120
objPinYinDic.Add "tao", -13107
objPinYinDic.Add "te", -13096
objPinYinDic.Add "teng", -13095
objPinYinDic.Add "ti", -13091
objPinYinDic.Add "tian", -13076
objPinYinDic.Add "tiao", -13068
objPinYinDic.Add "tie", -13063
objPinYinDic.Add "ting", -13060
objPinYinDic.Add "tong", -12888
objPinYinDic.Add "tou", -12875
objPinYinDic.Add "tu", -12871
objPinYinDic.Add "tuan", -12860
objPinYinDic.Add "tui", -12858
objPinYinDic.Add "tun", -12852
objPinYinDic.Add "tuo", -12849
objPinYinDic.Add "wa", -12838
objPinYinDic.Add "wai", -12831
objPinYinDic.Add "wan", -12829
objPinYinDic.Add "wang", -12812
objPinYinDic.Add "wei", -12802
objPinYinDic.Add "wen", -12607
objPinYinDic.Add "weng", -12597
objPinYinDic.Add "wo", -12594
objPinYinDic.Add "wu", -12585
objPinYinDic.Add "xi", -12556
objPinYinDic.Add "xia", -12359
objPinYinDic.Add "xian", -12346
objPinYinDic.Add "xiang", -12320
objPinYinDic.Add "xiao", -12300
objPinYinDic.Add "xie", -12120
objPinYinDic.Add "xin", -12099
objPinYinDic.Add "xing", -12089
objPinYinDic.Add "xiong", -12074
objPinYinDic.Add "xiu", -12067
objPinYinDic.Add "xu", -12058
objPinYinDic.Add "xuan", -12039
objPinYinDic.Add "xue", -11867
objPinYinDic.Add "xun", -11861
objPinYinDic.Add "ya", -11847
objPinYinDic.Add "yan", -11831
objPinYinDic.Add "yang", -11798
objPinYinDic.Add "yao", -11781
objPinYinDic.Add "ye", -11604
objPinYinDic.Add "yi", -11589
objPinYinDic.Add "yin", -11536
objPinYinDic.Add "ying", -11358
objPinYinDic.Add "yo", -11340
objPinYinDic.Add "yong", -11339
objPinYinDic.Add "you", -11324
objPinYinDic.Add "yu", -11303
objPinYinDic.Add "yuan", -11097
objPinYinDic.Add "yue", -11077
objPinYinDic.Add "yun", -11067
objPinYinDic.Add "za", -11055
objPinYinDic.Add "zai", -11052
objPinYinDic.Add "zan", -11045
objPinYinDic.Add "zang", -11041
objPinYinDic.Add "zao", -11038
objPinYinDic.Add "ze", -11024
objPinYinDic.Add "zei", -11020
objPinYinDic.Add "zen", -11019
objPinYinDic.Add "zeng", -11018
objPinYinDic.Add "zha", -11014
objPinYinDic.Add "zhai", -10838
objPinYinDic.Add "zhan", -10832
objPinYinDic.Add "zhang", -10815
objPinYinDic.Add "zhao", -10800
objPinYinDic.Add "zhe", -10790
objPinYinDic.Add "zhen", -10780
objPinYinDic.Add "zheng", -10764
objPinYinDic.Add "zhi", -10587
objPinYinDic.Add "zhong", -10544
objPinYinDic.Add "zhou", -10533
objPinYinDic.Add "zhu", -10519
objPinYinDic.Add "zhua", -10331
objPinYinDic.Add "zhuai", -10329
objPinYinDic.Add "zhuan", -10328
objPinYinDic.Add "zhuang", -10322
objPinYinDic.Add "zhui", -10315
objPinYinDic.Add "zhun", -10309
objPinYinDic.Add "zhuo", -10307
objPinYinDic.Add "zi", -10296
objPinYinDic.Add "zong", -10281
objPinYinDic.Add "zou", -10274
objPinYinDic.Add "zu", -10270
objPinYinDic.Add "zuan", -10262
objPinYinDic.Add "zui", -10260
objPinYinDic.Add "zun", -10256
objPinYinDic.Add "zuo", -10254
Dim arrPinYin As Variant
Dim arrPinYinCode As Variant
Dim i As Integer
Dim intIndex As Integer
Dim intHanZiAsc As Integer
Dim strResult As String
strResult = ""
For intIndex = 1 To Len(strHanZi)
intHanZiAsc = Asc(Mid(strHanZi, intIndex, 1))
If intHanZiAsc > 0 And intHanZiAsc < 160 Then
strResult = Chr(intHanZiAsc)
Else
If intHanZiAsc < -20319 Or intHanZiAsc > -10247 Then
strResult = strResult & ""
Else
arrPinYin = objPinYinDic.Items
arrPinYinCode = objPinYinDic.Keys
For i = objPinYinDic.Count - 1 To 0 Step -1
If arrPinYin(i) <= intHanZiAsc Then Exit For
Next
If i >= LBound(arrPinYin) And i <= UBound(arrPinYin) Then ''防止越界
strResult = strResult & arrPinYinCode(i)
Else
strResult = strResult & ""
End If
End If
End If
Next
gGetPinYin = strResult
End Function
问题有很多,我只是随便弄了一下,以后再修改
1.空字符串没有处理
2.标点符号没有处理
3.不支持只输出首字母
4.多音字无法分辩
5.字典难以维护,错了一个很难查出来,等我重新想个办法
6.先好好的弄懂,拼音的编码原理,再弄懂汉字的编码原理
7.感谢你,很有耐心的看完我罗嗦,如果你能完善,请告诉我,谢谢。
本文地址:http://com.8s8s.com/it/it43755.htm