您的位置:程序门 -> vb -> 基础类



如何获得输入汉字的拼音缩写?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何获得输入汉字的拼音缩写?
发表于:2007-07-20 20:56:54 楼主

          有2个文本框,在第一个文本框中输入中文汉字,要求在第二个文本框中显示出输入汉字的拼音缩写,如输入“爱好者乐园”,要求输出“ahzly”,就是每个汉字拼音的第一个字母。

谢谢!
发表于:2007-07-20 21:11:261楼 得分:0
找个库把文字翻译成拼音
发表于:2007-07-20 22:23:072楼 得分:0
这里有:
http://www.egooglet.com/static_html/200511072108063740admin.html
发表于:2007-07-21 00:50:353楼 得分:0
中文acs码就是根据拼音来排序的~
发表于:2007-07-21 13:28:514楼 得分:0
先把26个字母分别对应的头个汉字找出来,有23个汉字,他们的asc码值是依次排列的.
拿你要求的汉字的asc码和这23个汉字的asc码进行比较,便能知道它的拼音的第一个字母的位置.

这23个汉字是:
啊,芭,擦,搭,蛾,发,噶,哈,击,喀,垃,妈,拿,哦,啪,期,然,撒,塌,挖,昔,压,匝
a   ,b   ,c   ,d   ,e   ,f   ,g   ,h   ,j   ,k   ,l   ,m   ,n   ,o   ,p   ,q   ,r   ,s   ,t   ,w   ,x   ,y   ,z  
发表于:2007-07-21 14:48:025楼 得分:0
根据qqstone说法写的代码,只对简体有用
dim   col   as   new   collection

private   sub   command1_click()
dim   str1   as   string,   ascii   as   integer,   i   as   integer
dim   j   as   integer
str1   =   text1.text
for   j   =   1   to   len(str1)
        ascii   =   asc(mid(str1,   j,   1))
        if   ascii   <   asc(left(col.item(1),   1))   then
                'debug.print   "不是简体汉字 "
        elseif   ascii   > =   asc( "匝 ")   and   ascii   <=   asc( "座 ")   then
              debug.print   "z ";
        elseif   ascii   >   asc( "座 ")   then
              '   debug.print   "不是简体汉字 "
        else
                for   i   =   1   to   col.count   -   1
                        if   ascii   > =   asc(left(col.item(i),   1))   and   ascii   <   asc(left(col.item(i   +   1),   1))   then
                                debug.print   right(col.item(i),   1);
                        end   if
                next   i
        end   if

next   j
debug.print
end   sub

private   sub   form_load()
col.add   "啊:a "
col.add   "芭:b "
col.add   "擦:c "
col.add   "搭:d "
col.add   "蛾:e "
col.add   "发:f "
col.add   "噶:g "
col.add   "哈:h "
col.add   "击:j "
col.add   "喀:k "
col.add   "垃:l "
col.add   "妈:m "
col.add   "拿:n "
col.add   "哦:o "
col.add   "啪:p "
col.add   "期:q "
col.add   "然:r "
col.add   "撒:s "
col.add   "塌:t "
col.add   "挖:w "
col.add   "昔:x "
col.add   "压:y "
col.add   "匝:z "
end   sub
发表于:2007-07-21 14:59:556楼 得分:0
不错,学习。
发表于:2007-07-22 14:20:537楼 得分:0
什么简体、繁体……统统搞定!
http://smallfairy.51.net/kitegirl/pyget.htm
发表于:2007-07-24 12:06:428楼 得分:0
楼上的,我去试了下,这个拼音表好像有点问题,一般多音字都能正确识别,可不是多音字的有时也会识判为根本不正确的多音字,怎么回事?
发表于:2007-07-24 14:44:499楼 得分:0
下个dll
发表于:2007-07-24 14:55:3510楼 得分:0
不錯的想法
頂了
发表于:2007-07-27 02:39:1911楼 得分:0
有些“不是多音字”的字其实也是多音字,只是有些读音比较罕见而已。比如“是”字很少有人注意到它还读“ti”。
多音字问题相当闹心,除非用词组判断解决,否则只能返回最接近的多音字。另有一个类似的闹心问题是简体转繁体,因为许多相同用途的简体字在繁体下是不同的。这两个问题都需要以词为单位解析来解决。
我上面程序的数据是来自拼音输入法的定义,因此没有优化多音字的常用顺序。
发表于:2007-09-03 11:40:4912楼 得分:0
option   explicit
function   getpychar(char)   as   string
        on   error   resume   next
        dim   tmp   as   string,   vs1   as   string
       
        if   asc(char)   > =   0   and   asc(char)   <=   127   then
                if   char   > =   "a "   and   char   <=   "z "   then
                        getpychar   =   chr(asc(char)   -   32)
                elseif   char   > =   "a "   and   char   <=   "z "   then
                        getpychar   =   char
                else
                        '如果是空格,排除
                        if   asc(char)   =   32   then
                              getpychar   =   " "
                        else
                        '
                                getpychar   =   char
                        end   if
                end   if
        else
                tmp   =   65536   +   asc(char)
                select   case   tmp
                        case   45217   to   45252:   getpychar   =   "a "
                        case   45253   to   45760:   getpychar   =   "b "
                        case   45761   to   46317:   getpychar   =   "c "
                        case   46318   to   46825:   getpychar   =   "d "
                        case   46826   to   47009:   getpychar   =   "e "
                        case   47010   to   47296:   getpychar   =   "f "
                        case   47297   to   47613:   getpychar   =   "g "
                        case   47614   to   48118:   getpychar   =   "h "
                        case   48119   to   49061:   getpychar   =   "j "
                        case   49062   to   49323:   getpychar   =   "k "
                        case   49324   to   49895:   getpychar   =   "l "
                        case   49896   to   50370:   getpychar   =   "m "
                        case   50371   to   50613:   getpychar   =   "n "
                        case   50614   to   50621:   getpychar   =   "o "
                        case   50622   to   50905:   getpychar   =   "p "
                        case   50906   to   51386:   getpychar   =   "q "
                        case   51387   to   51445:   getpychar   =   "r "
                        case   51446   to   52217:   getpychar   =   "s "
                        case   52218   to   52697:   getpychar   =   "t "
                        case   52698   to   52979:   getpychar   =   "w "
                        case   52980   to   53640:   getpychar   =   "x "
                        case   53689   to   54480:   getpychar   =   "y "
                        case   54481   to   55289:   getpychar   =   "z "
                        case   else:   getpychar   =   "% "
                end   select
        end   if
end   function

function   getpy(str)
dim   i   as   long
        for   i   =   1   to   len(str)
                getpy   =   getpy   &   getpychar(mid(str,   i,   1))
        next   i
end   function
发表于:2007-09-03 11:42:4013楼 得分:0
再在第一个文本框的键盘按下事件中调用上述函数getpy
发表于:2007-09-03 13:06:4914楼 得分:0
楼上的函数对如下汉字是无能为力的,而且,实际上有很多这样的汉字。
“蓓葆芙霏琛晖昊瑾颉菁霁姣轲琨珑璐岚蔺靓闵霈菁琪祺樵麒晟佘嵩韬婷覃霆炜玮雯璇庠鑫曦轶赟闫滢瑜毓嫣煜烨晏瑛谌陟璋”
我的全部简体汉字拼音首字母解决方案:
clshpy.cls文件
option   explicit
private   sectable   as   string
public   function   getpy(optional   byval   s   as   string   =   " ")   as   string
        dim   t1   as   string
        dim   a   as   integer
        if   len(s)   =   0   then   exit   function
        a   =   asc(s)
        if   a   <   0   then
                       
                        if   a   >   &hb0a0   and   a   <   &hb0c5   then
                                getpy   =   "a "
                                exit   function
                        end   if
                       
                        if   a   <   &hb2c1   then
                                getpy   =   "b "
                                exit   function
                        end   if
                       
                        if   a   <   &hb4ee   then
                                getpy   =   "c "
                                exit   function
                        end   if
                       
                        if   a   <   &hb6ea   then
                                getpy   =   "d "
                                exit   function
                        end   if
                        if   a   <   &hb7a2   then
                                getpy   =   "e "
                                exit   function
                        end   if
                        if   a   <   &hb8c1   then
                                getpy   =   "f "
                                exit   function
                        end   if
                        if   a   <   &hb9fe   then
                                getpy   =   "g "
                                exit   function
                        end   if
                        if   a   <   &hbbf7   then
                                getpy   =   "h "
                                exit   function
                        end   if
                        if   a   <   &hbfa6   then
                                getpy   =   "j "
                                exit   function
                        end   if
                        if   a   <   &hc0ac   then
                                getpy   =   "k "
                                exit   function
                        end   if
                        if   a   <   &hc2e8   then
                                getpy   =   "l "
                                exit   function
                        end   if
                        if   a   <   &hc4c3   then
                                getpy   =   "m "
                                exit   function
                        end   if
                        if   a   <   &hc5b6   then
                                getpy   =   "n "
                                exit   function
                        end   if
                        if   a   <   &hc5be   then
                                getpy   =   "o "
                                exit   function
                        end   if
                        if   a   <   &hc6da   then
                                getpy   =   "p "
                                exit   function
                        end   if
                        if   a   <   &hc8bb   then
                                getpy   =   "q "
                                exit   function
                        end   if
                        if   a   <   &hc8f6   then
                                getpy   =   "r "
                                exit   function
                        end   if
                        if   a   <   &hcbfa   then
                                getpy   =   "s "
                                exit   function
                        end   if
                        if   a   <   &hcdda   then
                                getpy   =   "t "
                                exit   function
                        end   if
                        if   a   <   &hcef4   then
                                getpy   =   "w "
                                exit   function
                        end   if
                        if   a   <   &hd1b9   then
                                getpy   =   "x "
                                exit   function
                        end   if
                        if   a   <   &hd4d1   then
                                getpy   =   "y "
                                exit   function
                        end   if
                        if   a   <   &hd7fa   then
                                getpy   =   "z "
                                exit   function
                        end   if
                       
                        getpy   =   getsecpy(s)
                       
        else
                getpy   =   lcase(s)
        end   if
       
end   function
private   function   getsecpy(byval   hz   as   string)   as   string
        dim   c   as   string
        dim   q   as   integer,   w   as   integer,   tabpos   as   integer
        'if   asc(hz)   > =   0   then   exit   function
        hz   =   hex(asc(hz))
        q   =   cdec( "&h "   &   left(hz,   2))   -   160
        w   =   cdec( "&h "   &   right(hz,   2))   -   160
        '在sectable中的位置
        tabpos   =   (q   -   56)   *   94   +   w
        if   tabpos   >   3008   then   exit   function
        getsecpy   =   lcase(mid(sectable,   tabpos,   1))
end   function

private   sub   class_initialize()
        sectable   =   "cjwgnspgcgnesypbtyyzdxykygtdjnnjqmbsgzscyjsyyqpgkbzgycywjkgkljywkpjqhytwddzlsymrypywwcckznkyygttngj "
        sectable   =   sectable   &   "eykkzytcjnmcylqlypysfqrpzslwbtgkjfyxjwzltbncxjjjjtxdttsqzycdxxhgckbphffsswybgmxlpbylllhlxspzmyjhsojn "
        sectable   =   sectable   &   "ghdzqyklgjhsgqzhxqgkezzwyscscjxyeyxadzpmdssmzjzqjyzcdjzwqjbdzbxgznzcpwhwxhqkmwfbpbydtjzzkqxylygxfpty "
        sectable   =   sectable   &   "jyyzpszlfchmqshgmxxsxjjsdcsbbqbefsjyhxwgzkpylqbgldlcdtnmayddkssngycsgxlyzaypnptsdkdylhgymylcxpycjndq "
        sectable   =   sectable   &   "jwxqxfyyfjlejpzrxccqwqqsbzkymgplbmjrqcflnymyqmtqyrbcjthztqfrxqhxmqjcjlyxgjmshzkbswyemyltxfsydsglycjq "
        sectable   =   sectable   &   "xsjnqbsctyhbftdcyzdjwyghqfsxwckqkxebptlpxjzsrmebwhjlbjslyysmdxlclqkxlhxjrzjmfqhxhwywsbhtrxxglhqhfnmn "
        sectable   =   sectable   &   "ykldyxzpylggtmtcfpnjjzyljtyanjgbjplqgdzyqyaxbkysecjsznslyzhzxlzcghpxzhznytdsbcjkdlz?yfmytlebbgqyzkgg "
        sectable   =   sectable   &   "ldndnyskjshdlyxbcghxypkdjmmzngmmclgezszxzjfznmlzzthcsydbdllsczdnlkjykjsycjlkwhqasdknhcsgaehdaashtcpl "
        sectable   =   sectable   &   "cpqybsdmpjlpcjoqlcdhjxysprchnwjnlhlyyqyhwzptczgwwmzffjqqqqyxaclbhkdjxdgmmydqxzllsygxgkjrywzwyclzmssj "
        sectable   =   sectable   &   "zldbydcpcxyhlxchyzjqsfqagmnyxpfrkssbjlyxysyglnscmhcwwmnzjjlxxhchsydsttxrycyxbyhcsmxjsznpwgpxxtaybgaj "
        sectable   =   sectable   &   "cxlysdccwzocwkccsbnhcpdyznfcyytyckxkybsqkkytqqxfcwchcykelzqbsqyjqcclmthsywhmktlkjlycxwheqqhtqkzpqsqs "
        sectable   =   sectable   &   "cfymmdmgbwhwlgsllysdlmlxpthmjhwljzyhzjxhtxjlhxrswlwzjcbxmhzqxsdzpmgfcsglsxymqshxpjxwmyqksmyplrthbxft "
        sectable   =   sectable   &   "pmhyxlchlhlzylxgsssstclsldclrpbhzhxyyfhbbgdmycnqqwlqhjjzywjzyejjdhpblqxtqkwhlchqxagtlxljxmslxhtzkzje "
        sectable   =   sectable   &   "cxjcjnmfbycsfywybjzgnysdzsqyrsljpclpwxsdwejbjcbcnaytwgmpapclyqpclzxsbnmsggfnzjjbzsfzyntxhplqkzczwals "
        sectable   =   sectable   &   "bccjxjyzgwkypsgxfzfcdkhjgxtlqfsgdslqwzkxtmhsbgzmjzrglyjbpmlmsxlzjqqhzyjczydjwbmjklddpmjegxyhylxhlqyq "
        sectable   =   sectable   &   "hkycwcjmyyxnatjhyccxzpcqlbzwwytwsqcmlpmyrjcccxfpznzzljplxxyztzlgdltcklyrzzgqtkjhhgjljaxfgfjzslcfdqzl "
        sectable   =   sectable   &   "clgjdjcsnzlljpjqdcclcjxmyzftsxgcgsbrzxjqqctzhgyqtjqqlzxjylylbcyamcstylpdjbyregklzyzhlyszqlznwczcllwj "
        sectable   =   sectable   &   "qjjjkdgjzolbbzppglghtgzxyghzmycnqsycyhbhgxkamtxyxnbskyzzgjzlqjdfcjxdygjqjjpmgwgjjjpkqsbgbmmcjssclpqp "
        sectable   =   sectable   &   "dxcdyykyfcjddyygywrhjrtgznyqldkljszzgzqzjgdykshpzmtlcpwnjyfyzdjcnmwescyglbtzcgmssllyxysxxbsjsbbsgghf "
        sectable   =   sectable   &   "jlypmzjnlyywdqshzxtyywhmcyhywdbxbtlmsyyyfsxjcstxxlhjhfssxzqhfzmzcztqcxzxrttdjhnnyzqqmtqdmmgyytxmjgdh "
        sectable   =   sectable   &   "cdyzbffallztdltfxmxqzdngwqdbdczjdxbzgsqqddjcmbkzffxmkdmdsyyszcmljdsynsprskmkmpcklgdbqtfzswtfgglypllj "
        sectable   =   sectable   &   "zhgjjgypzltcsmcnbtjbqfkthpyzgkpbbymtdssxtbnpdkleycjnycdykzddhqhsdzsctarlltkzlgecllkjlqjaqnbdkkghpjtz "
        sectable   =   sectable   &   "qksecshalqfmmgjnlyjbbtmlyzxdcjpldlpcqdhzycbzsczbzmsljflkrzjsnfrgjhxpdhyjybzgdlqcsezgxlblhyxtwmabchec "
        sectable   =   sectable   &   "mwyjyzlljjyhlgbdjlslygkdzpzxjyyzlwcxszfgwyydlyhcljscmbjhblyzlycblydpdqysxqzbytdkyxjyycnrjmpdqgklcljb "
        sectable   =   sectable   &   "ctbjddbblblczqrpsxjcjlzcshltoljnmdddlngkathqhjhykheznmshrphqqjchgmfprxhjgdychgklyrzqlcyqjnzsqtkqjyms "
        sectable   =   sectable   &   "zswlcfqqqxyfggyptqwlmcrnfkkfsyylqbmqammmyxctpshcptxxzzsmphpshmclmldqfyqxszyjdjjzzhqpdszglstjbckbxyqz "
        sectable   =   sectable   &   "jsgpsxqzqzrqtbdkyxzkhhgflbcsmdldgdzdblzyycxnncsybzbfglzzxswmsccmqnjqsbdqsjtxxmbltxcclzshzcxrqjgjylxz "
        sectable   =   sectable   &   "fjphymzqqydfqjqlzznzjcdgzygztxmzysctlkphtxhtlbjxjlxscdqxcbbtjfqzfsltjbtkqbxxjjljchczdbzjdczjdcprnpqc "
        sectable   =   sectable   &   "jpfczlclzxzdmxmphjsgzgszzqlylwtjpfsyaxmcjbtzyycwmytzsjjlqcqlwzmalbxyfbpnlsfhtgjwejjxxglljstgshjqlzfk "
        sectable   =   sectable   &   "cgnndszfdeqfhbsaqtgylbxmmygszldydqmjjrgbjtkgdhgkblqkbdmbylxwcxyttybkmrtjzxqjbhlmhmjjzmqasldcyxyqdlqcafywyxqhz "

end   sub
发表于:2007-09-03 19:08:2515楼 得分:0
public   function   py(mystr   as   string)   as   string
    if   asc(mystr)   <   0   then
        if   asc(left(mystr,   1))   <   asc( "啊 ")   then
              py   =   "0 "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "啊 ")   and   asc(left(mystr,   1))   <   asc( "芭 ")   then
              py   =   "a "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "芭 ")   and   asc(left(mystr,   1))   <   asc( "擦 ")   then
              py   =   "b "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "擦 ")   and   asc(left(mystr,   1))   <   asc( "搭 ")   then
              py   =   "c "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "搭 ")   and   asc(left(mystr,   1))   <   asc( "蛾 ")   then
              py   =   "d "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "蛾 ")   and   asc(left(mystr,   1))   <   asc( "发 ")   then
              py   =   "e "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "发 ")   and   asc(left(mystr,   1))   <   asc( "噶 ")   then
              py   =   "f "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "噶 ")   and   asc(left(mystr,   1))   <   asc( "哈 ")   then
              py   =   "g "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "哈 ")   and   asc(left(mystr,   1))   <   asc( "击 ")   then
              py   =   "h "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "击 ")   and   asc(left(mystr,   1))   <   asc( "喀 ")   then
              py   =   "j "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "喀 ")   and   asc(left(mystr,   1))   <   asc( "垃 ")   then
              py   =   "k "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "垃 ")   and   asc(left(mystr,   1))   <   asc( "妈 ")   then
              py   =   "l "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "妈 ")   and   asc(left(mystr,   1))   <   asc( "拿 ")   then
              py   =   "m "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "拿 ")   and   asc(left(mystr,   1))   <   asc( "哦 ")   then
              py   =   "n "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "哦 ")   and   asc(left(mystr,   1))   <   asc( "啪 ")   then
              py   =   "o "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "啪 ")   and   asc(left(mystr,   1))   <   asc( "期 ")   then
              py   =   "p "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "期 ")   and   asc(left(mystr,   1))   <   asc( "然 ")   then
              py   =   "q "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "然 ")   and   asc(left(mystr,   1))   <   asc( "撒 ")   then
              py   =   "r "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "撒 ")   and   asc(left(mystr,   1))   <   asc( "塌 ")   then
              py   =   "s "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "塌 ")   and   asc(left(mystr,   1))   <   asc( "挖 ")   then
              py   =   "t "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "挖 ")   and   asc(left(mystr,   1))   <   asc( "昔 ")   then
              py   =   "w "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "昔 ")   and   asc(left(mystr,   1))   <   asc( "压 ")   then
              py   =   "x "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "压 ")   and   asc(left(mystr,   1))   <   asc( "匝 ")   then
              py   =   "y "
              exit   function
        end   if
        if   asc(left(mystr,   1))   > =   asc( "匝 ")   then
              py   =   "z "
              exit   function
        end   if
    else
        if   ucase(mystr)   <=   "z "   and   ucase(mystr)   > =   "a "   then
              py   =   ucase(left(mystr,   1))
            else
              py   =   mystr
        end   if
    end   if
end   function


快速检索

最新资讯
热门点击