zoukankan      html  css  js  c++  java
  • 实现汉字转拼音

    http://wallimn.javaeye.com/blog/374917

     方法一:

    C#代码
    1. /// <summary>   
    2.         /// 生成拼音简码   
    3.         /// </summary>   
    4.         /// <param name="unicodeString">Unicode编码字符串</param>   
    5.         /// <returns>拼音简码:string</returns>   
    6.         public   static   string  GetPinyinCode( string  unicodeString)  
    7.         {  
    8.             int  i = 0;  
    9.             ushort  key = 0;  
    10.             string  strResult =  string .Empty;             //创建两个不同的encoding对象   
    11.             Encoding unicode = Encoding.Unicode;  
    12.             //创建GBK码对象   
    13.             Encoding gbk = Encoding.GetEncoding(936);  
    14.             //将unicode字符串转换为字节   
    15.             byte [] unicodeBytes = unicode.GetBytes(unicodeString);  
    16.             //再转化为GBK码   
    17.             byte [] gbkBytes = Encoding.Convert(unicode, gbk, unicodeBytes);  
    18.             while  (i < gbkBytes.Length)  
    19.             {  
    20.                 //如果为数字/字母/其他ASCII符号   
    21.                 if  (gbkBytes <= 127)  
    22.                 {  
    23.                     strResult = strResult + (char )gbkBytes;  
    24.                     i++;  
    25.                 }  
    26.                 #region 否则生成汉字拼音简码,取拼音首字母   
    27.                 else   
    28.                 {  
    29.                     key = (ushort )(gbkBytes * 256 + gbkBytes[i + 1]);  
    30.                     if  (key >=  '/uB0A1'  && key <=  '/uB0C4' )  
    31.                     {  
    32.                         strResult = strResult + "A" ;  
    33.                     }  
    34.                     else   if  (key >=  '/uB0C5'  && key <=  '/uB2C0' )  
    35.                     {  
    36.                         strResult = strResult + "B" ;  
    37.                     }  
    38.                     else   if  (key >=  '/uB2C1'  && key <=  '/uB4ED' )  
    39.                     {  
    40.                         strResult = strResult + "C" ;  
    41.                     }  
    42.                     else   if  (key >=  '/uB4EE'  && key <=  '/uB6E9' )  
    43.                     {  
    44.                         strResult = strResult + "D" ;  
    45.                     }  
    46.                     else   if  (key >=  '/uB6EA'  && key <=  '/uB7A1' )  
    47.                     {  
    48.                         strResult = strResult + "E" ;  
    49.                     }  
    50.                     else   if  (key >=  '/uB7A2'  && key <=  '/uB8C0' )  
    51.                     {  
    52.                         strResult = strResult + "F" ;  
    53.                     }  
    54.                     else   if  (key >=  '/uB8C1'  && key <=  '/uB9FD' )  
    55.                     {  
    56.                         strResult = strResult + "G" ;  
    57.                     }  
    58.                     else   if  (key >=  '/uB9FE'  && key <=  '/uBBF6' )  
    59.                     {  
    60.                         strResult = strResult + "H" ;  
    61.                     }  
    62.                     else   if  (key >=  '/uBBF7'  && key <=  '/uBFA5' )  
    63.                     {  
    64.                         strResult = strResult + "J" ;  
    65.                     }  
    66.                     else   if  (key >=  '/uBFA6'  && key <=  '/uC0AB' )  
    67.                     {  
    68.                         strResult = strResult + "K" ;  
    69.                     }  
    70.                     else   if  (key >=  '/uC0AC'  && key <=  '/uC2E7' )  
    71.                     {  
    72.                         strResult = strResult + "L" ;  
    73.                     }  
    74.                     else   if  (key >=  '/uC2E8'  && key <=  '/uC4C2' )  
    75.                     {  
    76.                         strResult = strResult + "M" ;  
    77.                     }  
    78.                     else   if  (key >=  '/uC4C3'  && key <=  '/uC5B5' )  
    79.                     {  
    80.                         strResult = strResult + "N" ;  
    81.                     }  
    82.                     else   if  (key >=  '/uC5B6'  && key <=  '/uC5BD' )  
    83.                     {  
    84.                         strResult = strResult + "O" ;  
    85.                     }  
    86.                     else   if  (key >=  '/uC5BE'  && key <=  '/uC6D9' )  
    87.                     {  
    88.                         strResult = strResult + "P" ;  
    89.                     }  
    90.                     else   if  (key >=  '/uC6DA'  && key <=  '/uC8BA' )  
    91.                     {  
    92.                         strResult = strResult + "Q" ;  
    93.                     }  
    94.                     else   if  (key >=  '/uC8BB'  && key <=  '/uC8F5' )  
    95.                     {  
    96.                         strResult = strResult + "R" ;  
    97.                     }  
    98.                     else   if  (key >=  '/uC8F6'  && key <=  '/uCBF9' )  
    99.                     {  
    100.                         strResult = strResult + "S" ;  
    101.                     }  
    102.                     else   if  (key >=  '/uCBFA'  && key <=  '/uCDD9' )  
    103.                     {  
    104.                         strResult = strResult + "T" ;  
    105.                     }  
    106.                     else   if  (key >=  '/uCDDA'  && key <=  '/uCEF3' )  
    107.                     {  
    108.                         strResult = strResult + "W" ;  
    109.                     }  
    110.                     else   if  (key >=  '/uCEF4'  && key <=  '/uD188' )  
    111.                     {  
    112.                         strResult = strResult + "X" ;  
    113.                     }  
    114.                     else   if  (key >=  '/uD1B9'  && key <=  '/uD4D0' )  
    115.                     {  
    116.                         strResult = strResult + "Y" ;  
    117.                     }  
    118.                     else   if  (key >=  '/uD4D1'  && key <=  '/uD7F9' )  
    119.                     {  
    120.                         strResult = strResult + "Z" ;  
    121.                     }  
    122.                     else   
    123.                     {  
    124.                         strResult = strResult + "?" ;  
    125.                     }  
    126.                     i = i + 2;  
    127.                 }  
    128.                 #endregion   
    129.             }//end while   
    130.             return  strResult;  
    131.         }  


    原文地址:http://qzone.qq.com/blog/47541785-1223276474
    方法二:

    C#代码
    1. static   public   string  GetChineseSpell( string  strText)  
    2. {  
    3. int  len = strText.Length;  
    4. string  myStr =  "" ;  
    5. for ( int  i=0;i<len;i++)  
    6. {  
    7. myStr += getSpell(strText.Substring(i,1));  
    8. }  
    9. return  myStr;  
    10. }  
    11.   
    12. static   public   string  getSpell( string  cnChar)  
    13. {  
    14. byte [] arrCN = Encoding.Default.GetBytes(cnChar);  
    15. if (arrCN.Length > 1)  
    16. {  
    17. int  area = ( short )arrCN[0];  
    18. int  pos = ( short )arrCN[1];  
    19. int  code = (area<<8) + pos;  
    20. int [] areacode = {45217,45253,45761,46318,46826,47010,47297,47614,48119,48119,49062,49324,49896,50371,50614,50622,50906,51387,51446,52218,52698,52698,52698,52980,53689,54481};  
    21. for ( int  i=0;i<26;i++)  
    22. {  
    23. int  max = 55290;  
    24. if (i != 25) max = areacode[i+1];  
    25. if (areacode[i]<=code && code<max)  
    26. {  
    27. return  Encoding.Default.GetString( new   byte []{( byte )(65+i)});  
    28. }  
    29. }  
    30. return   "*" ;  
    31. }  
    32. else   return  cnChar;  
    33. }  


    原文地址:http://www.d9soft.com/article/266/Article22540_1.htm
    方法三:

    C#代码
    1.     #region 拼音编码   
    2.     private   static   int [] pyValue =  new   int []  
    3. {  
    4. -20319,-20317,-20304,-20295,-20292,-20283,-20265,-20257,-20242,-20230,-20051,-20036,  
    5. -20032,-20026,-20002,-19990,-19986,-19982,-19976,-19805,-19784,-19775,-19774,-19763,  
    6. -19756,-19751,-19746,-19741,-19739,-19728,-19725,-19715,-19540,-19531,-19525,-19515,  
    7. -19500,-19484,-19479,-19467,-19289,-19288,-19281,-19275,-19270,-19263,-19261,-19249,  
    8. -19243,-19242,-19238,-19235,-19227,-19224,-19218,-19212,-19038,-19023,-19018,-19006,  
    9. -19003,-18996,-18977,-18961,-18952,-18783,-18774,-18773,-18763,-18756,-18741,-18735,  
    10. -18731,-18722,-18710,-18697,-18696,-18526,-18518,-18501,-18490,-18478,-18463,-18448,  
    11. -18447,-18446,-18239,-18237,-18231,-18220,-18211,-18201,-18184,-18183, -18181,-18012,  
    12. -17997,-17988,-17970,-17964,-17961,-17950,-17947,-17931,-17928,-17922,-17759,-17752,  
    13. -17733,-17730,-17721,-17703,-17701,-17697,-17692,-17683,-17676,-17496,-17487,-17482,  
    14. -17468,-17454,-17433,-17427,-17417,-17202,-17185,-16983,-16970,-16942,-16915,-16733,  
    15. -16708,-16706,-16689,-16664,-16657,-16647,-16474,-16470,-16465,-16459,-16452,-16448,  
    16. -16433,-16429,-16427,-16423,-16419,-16412,-16407,-16403,-16401,-16393,-16220,-16216,  
    17. -16212,-16205,-16202,-16187,-16180,-16171,-16169,-16158,-16155,-15959,-15958,-15944,  
    18. -15933,-15920,-15915,-15903,-15889,-15878,-15707,-15701,-15681,-15667,-15661,-15659,  
    19. -15652,-15640,-15631,-15625,-15454,-15448,-15436,-15435,-15419,-15416,-15408,-15394,  
    20. -15385,-15377,-15375,-15369,-15363,-15362,-15183,-15180,-15165,-15158,-15153,-15150,  
    21. -15149,-15144,-15143,-15141,-15140,-15139,-15128,-15121,-15119,-15117,-15110,-15109,  
    22. -14941,-14937,-14933,-14930,-14929,-14928,-14926,-14922,-14921,-14914,-14908,-14902,  
    23. -14894,-14889,-14882,-14873,-14871,-14857,-14678,-14674,-14670,-14668,-14663,-14654,  
    24. -14645,-14630,-14594,-14429,-14407,-14399,-14384,-14379,-14368,-14355,-14353,-14345,  
    25. -14170,-14159,-14151,-14149,-14145,-14140,-14137,-14135,-14125,-14123,-14122,-14112,  
    26. -14109,-14099,-14097,-14094,-14092,-14090,-14087,-14083,-13917,-13914,-13910,-13907,  
    27. -13906,-13905,-13896,-13894,-13878,-13870,-13859,-13847,-13831,-13658,-13611,-13601,  
    28. -13406,-13404,-13400,-13398,-13395,-13391,-13387,-13383,-13367,-13359,-13356,-13343,  
    29. -13340,-13329,-13326,-13318,-13147,-13138,-13120,-13107,-13096,-13095,-13091,-13076,  
    30. -13068,-13063,-13060,-12888,-12875,-12871,-12860,-12858,-12852,-12849,-12838,-12831,  
    31. -12829,-12812,-12802,-12607,-12597,-12594,-12585,-12556,-12359,-12346,-12320,-12300,  
    32. -12120,-12099,-12089,-12074,-12067,-12058,-12039,-11867,-11861,-11847,-11831,-11798,  
    33. -11781,-11604,-11589,-11536,-11358,-11340,-11339,-11324,-11303,-11097,-11077,-11067,  
    34. -11055,-11052,-11045,-11041,-11038,-11024,-11020,-11019,-11018,-11014,-10838,-10832,  
    35. -10815,-10800,-10790,-10780,-10764,-10587,-10544,-10533,-10519,-10331,-10329,-10328,  
    36. -10322,-10315,-10309,-10307,-10296,-10281,-10274,-10270,-10262,-10260,-10256,-10254  
    37. };  
    38.     private   static   string [] pyName =  new   string []  
    39. {  
    40. "A" , "Ai" , "An" , "Ang" , "Ao" , "Ba" , "Bai" , "Ban" , "Bang" , "Bao" , "Bei" , "Ben" ,  
    41. "Beng" , "Bi" , "Bian" , "Biao" , "Bie" , "Bin" , "Bing" , "Bo" , "Bu" , "Ba" , "Cai" , "Can" ,  
    42. "Cang" , "Cao" , "Ce" , "Ceng" , "Cha" , "Chai" , "Chan" , "Chang" , "Chao" , "Che" , "Chen" , "Cheng" ,  
    43. "Chi" , "Chong" , "Chou" , "Chu" , "Chuai" , "Chuan" , "Chuang" , "Chui" , "Chun" , "Chuo" , "Ci" , "Cong" ,  
    44. "Cou" , "Cu" , "Cuan" , "Cui" , "Cun" , "Cuo" , "Da" , "Dai" , "Dan" , "Dang" , "Dao" , "De" ,  
    45. "Deng" , "Di" , "Dian" , "Diao" , "Die" , "Ding" , "Diu" , "Dong" , "Dou" , "Du" , "Duan" , "Dui" ,  
    46. "Dun" , "Duo" , "E" , "En" , "Er" , "Fa" , "Fan" , "Fang" , "Fei" , "Fen" , "Feng" , "Fo" ,  
    47. "Fou" , "Fu" , "Ga" , "Gai" , "Gan" , "Gang" , "Gao" , "Ge" , "Gei" , "Gen" , "Geng" , "Gong" ,  
    48. "Gou" , "Gu" , "Gua" , "Guai" , "Guan" , "Guang" , "Gui" , "Gun" , "Guo" , "Ha" , "Hai" , "Han" ,  
    49. "Hang" , "Hao" , "He" , "Hei" , "Hen" , "Heng" , "Hong" , "Hou" , "Hu" , "Hua" , "Huai" , "Huan" ,  
    50. "Huang" , "Hui" , "Hun" , "Huo" , "Ji" , "Jia" , "Jian" , "Jiang" , "Jiao" , "Jie" , "Jin" , "Jing" ,  
    51. "Jiong" , "Jiu" , "Ju" , "Juan" , "Jue" , "Jun" , "Ka" , "Kai" , "Kan" , "Kang" , "Kao" , "Ke" ,  
    52. "Ken" , "Keng" , "Kong" , "Kou" , "Ku" , "Kua" , "Kuai" , "Kuan" , "Kuang" , "Kui" , "Kun" , "Kuo" ,  
    53. "La" , "Lai" , "Lan" , "Lang" , "Lao" , "Le" , "Lei" , "Leng" , "Li" , "Lia" , "Lian" , "Liang" ,  
    54. "Liao" , "Lie" , "Lin" , "Ling" , "Liu" , "Long" , "Lou" , "Lu" , "Lv" , "Luan" , "Lue" , "Lun" ,  
    55. "Luo" , "Ma" , "Mai" , "Man" , "Mang" , "Mao" , "Me" , "Mei" , "Men" , "Meng" , "Mi" , "Mian" ,  
    56. "Miao" , "Mie" , "Min" , "Ming" , "Miu" , "Mo" , "Mou" , "Mu" , "Na" , "Nai" , "Nan" , "Nang" ,  
    57. "Nao" , "Ne" , "Nei" , "Nen" , "Neng" , "Ni" , "Nian" , "Niang" , "Niao" , "Nie" , "Nin" , "Ning" ,  
    58. "Niu" , "Nong" , "Nu" , "Nv" , "Nuan" , "Nue" , "Nuo" , "O" , "Ou" , "Pa" , "Pai" , "Pan" ,  
    59. "Pang" , "Pao" , "Pei" , "Pen" , "Peng" , "Pi" , "Pian" , "Piao" , "Pie" , "Pin" , "Ping" , "Po" ,  
    60. "Pu" , "Qi" , "Qia" , "Qian" , "Qiang" , "Qiao" , "Qie" , "Qin" , "Qing" , "Qiong" , "Qiu" , "Qu" ,  
    61. "Quan" , "Que" , "Qun" , "Ran" , "Rang" , "Rao" , "Re" , "Ren" , "Reng" , "Ri" , "Rong" , "Rou" ,  
    62. "Ru" , "Ruan" , "Rui" , "Run" , "Ruo" , "Sa" , "Sai" , "San" , "Sang" , "Sao" , "Se" , "Sen" ,  
    63. "Seng" , "Sha" , "Shai" , "Shan" , "Shang" , "Shao" , "She" , "Shen" , "Sheng" , "Shi" , "Shou" , "Shu" ,  
    64. "Shua" , "Shuai" , "Shuan" , "Shuang" , "Shui" , "Shun" , "Shuo" , "Si" , "Song" , "Sou" , "Su" , "Suan" ,  
    65. "Sui" , "Sun" , "Suo" , "Ta" , "Tai" , "Tan" , "Tang" , "Tao" , "Te" , "Teng" , "Ti" , "Tian" ,  
    66. "Tiao" , "Tie" , "Ting" , "Tong" , "Tou" , "Tu" , "Tuan" , "Tui" , "Tun" , "Tuo" , "Wa" , "Wai" ,  
    67. "Wan" , "Wang" , "Wei" , "Wen" , "Weng" , "Wo" , "Wu" , "Xi" , "Xia" , "Xian" , "Xiang" , "Xiao" ,  
    68. "Xie" , "Xin" , "Xing" , "Xiong" , "Xiu" , "Xu" , "Xuan" , "Xue" , "Xun" , "Ya" , "Yan" , "Yang" ,  
    69. "Yao" , "Ye" , "Yi" , "Yin" , "Ying" , "Yo" , "Yong" , "You" , "Yu" , "Yuan" , "Yue" , "Yun" ,  
    70. "Za" "Zai" , "Zan" , "Zang" , "Zao" , "Ze" , "Zei" , "Zen" , "Zeng" , "Zha" , "Zhai" , "Zhan" ,  
    71. "Zhang" , "Zhao" , "Zhe" , "Zhen" , "Zheng" , "Zhi" , "Zhong" , "Zhou" , "Zhu" , "Zhua" , "Zhuai" , "Zhuan" ,  
    72. "Zhuang" , "Zhui" , "Zhun" , "Zhuo" , "Zi" , "Zong" , "Zou" , "Zu" , "Zuan" , "Zui" , "Zun" , "Zuo"   
    73. };  
    74.     #endregion 拼音编码   
    75.     /// <summary>   
    76.     /// 从字符串中获取汉字拼音首字母,不是汉字则原样输出   
    77.     /// </summary>   
    78.     /// <param name="hz"></param>   
    79.     /// <returns></returns>   
    80.     public   static   string  GetFirstPYLetter( string  hz)  
    81.     {  
    82.         string  ls_second_eng =  "CJWGNSPGCGNESYPBTYYZDXYKYGTDJNNJQMBSGZSCYJSYYQPGKBZGYCYWJKGKLJSWKPJQHYTWDDZLSGMRYPYWWCCKZNKYDGTTNGJEYKKZYTCJNMCYLQLYPYQFQRPZSLWBTGKJFYXJWZLTBNCXJJJJZXDTTSQZYCDXXHGCKBPHFFSSWYBGMXLPBYLLLHLXSPZMYJHSOJNGHDZQYKLGJHSGQZHXQGKEZZWYSCSCJXYEYXADZPMDSSMZJZQJYZCDJZWQJBDZBXGZNZCPWHKXHQKMWFBPBYDTJZZKQHYLYGXFPTYJYYZPSZLFCHMQSHGMXXSXJJSDCSBBQBEFSJYHWWGZKPYLQBGLDLCCTNMAYDDKSSNGYCSGXLYZAYBNPTSDKDYLHGYMYLCXPYCJNDQJWXQXFYYFJLEJBZRXCCQWQQSBNKYMGPLBMJRQCFLNYMYQMSQTRBCJTHZTQFRXQ"  +  
    83.       "HXMJJCJLXQGJMSHZKBSWYEMYLTXFSYDSGLYCJQX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YLQBMQAMMMYXCTPSHCPTXXZZSM"  +  "ALBXYFBPNLSFHTGJWEJJXXGLLJSTGSHJQLZFKCGNNDSZFDEQFHBSAQTGLLBXMMYGSZLDYDQMJJRGBJTKGDHGKBLQKBDMBYLXWCXYTTYBKMRTJZXQJBHLMHMJJZMQASLDCYXYQDLQCAFYWYXQHZ" ;  
    88.         string  ls_second_ch =  "亍丌兀丐廿卅丕亘丞鬲孬噩丨禺丿匕乇夭爻卮氐囟胤馗毓睾鼗丶亟"  +  
    89.       " 鼐乜乩亓芈孛啬嘏仄厍厝厣厥厮靥赝匚叵匦匮匾赜卦卣刂刈刎刭刳刿剀剌剞剡剜蒯剽劂劁劐劓冂罔亻仃仉仂仨仡仫仞伛仳伢佤仵伥伧伉伫佞佧攸佚佝佟佗伲伽佶佴侑 侉侃侏佾佻侪佼侬侔俦俨俪俅俚俣俜俑俟俸倩偌俳倬倏倮倭俾倜倌倥倨偾偃偕偈偎偬偻傥傧傩傺僖儆僭僬僦僮儇儋仝氽佘佥俎龠氽籴兮巽黉馘冁夔勹匍訇匐凫夙兕亠 兖亳衮袤亵脔裒禀嬴蠃羸冫冱冽冼凇冖冢冥讠讦讧讪讴讵讷诂诃诋诏诎诒诓诔诖诘诙诜诟诠诤诨诩诮诰诳诶诹诼诿谀谂谄谇谌谏谑谒谔谕谖谙谛谘谝谟谠谡谥谧谪谫 谮谯谲谳谵谶卩卺阝阢阡阱阪阽阼"  +  
    90.       " 陂陉陔陟陧陬陲陴隈隍隗隰邗邛邝邙邬邡邴邳邶邺邸邰郏郅邾郐郄郇郓郦郢郜郗郛郫郯郾鄄鄢鄞鄣鄱鄯鄹酃酆刍奂劢劬劭劾哿勐勖勰叟燮矍廴凵凼鬯厶弁畚巯坌垩垡 塾墼壅壑圩圬圪圳圹圮圯坜圻坂坩垅坫垆坼坻坨坭坶坳垭垤垌垲埏垧垴垓垠埕埘埚埙埒垸埴埯埸埤埝堋堍埽埭堀堞堙塄堠塥塬墁墉墚墀馨鼙懿艹艽艿芏芊芨芄芎芑芗 芙芫芸芾芰苈苊苣芘芷芮苋苌苁芩芴芡芪芟苄苎芤苡茉苷苤茏茇苜苴苒苘茌苻苓茑茚茆茔茕苠苕茜荑荛荜茈莒茼茴茱莛荞茯荏荇荃荟荀茗荠茭茺茳荦荥荨茛荩荬荪荭 荮莰荸莳莴莠莪莓莜莅荼莶莩荽莸荻"  +  
    91.       " 莘莞莨莺莼菁萁菥菘堇萘萋菝菽菖萜萸萑萆菔菟萏萃菸菹菪菅菀萦菰菡葜葑葚葙葳蒇蒈葺蒉葸萼葆葩葶蒌蒎萱葭蓁蓍蓐蓦蒽蓓蓊蒿蒺蓠蒡蒹蒴蒗蓥蓣蔌甍蔸蓰蔹蔟蔺 蕖蔻蓿蓼蕙蕈蕨蕤蕞蕺瞢蕃蕲蕻薤薨薇薏蕹薮薜薅薹薷薰藓藁藜藿蘧蘅蘩蘖蘼廾弈夼奁耷奕奚奘匏尢尥尬尴扌扪抟抻拊拚拗拮挢拶挹捋捃掭揶捱捺掎掴捭掬掊捩掮掼 揲揸揠揿揄揞揎摒揆掾摅摁搋搛搠搌搦搡摞撄摭撖摺撷撸撙撺擀擐擗擤擢攉攥攮弋忒甙弑卟叱叽叩叨叻吒吖吆呋呒呓呔呖呃吡呗呙吣吲咂咔呷呱呤咚咛咄呶呦咝哐咭 哂咴哒咧咦哓哔呲咣哕咻咿哌哙哚哜咩"  +  
    92.       " 咪咤哝哏哞唛哧唠哽唔哳唢唣唏唑唧唪啧喏喵啉啭啁啕唿啐唼唷啖啵啶啷唳唰啜喋嗒喃喱喹喈喁喟啾嗖喑啻嗟喽喾喔喙嗪嗷嗉嘟嗑嗫嗬嗔嗦嗝嗄嗯嗥嗲嗳嗌嗍嗨嗵嗤 辔嘞嘈嘌嘁嘤嘣嗾嘀嘧嘭噘嘹噗嘬噍噢噙噜噌噔嚆噤噱噫噻噼嚅嚓嚯囔囗囝囡囵囫囹囿圄圊圉圜帏帙帔帑帱帻帼帷幄幔幛幞幡岌屺岍岐岖岈岘岙岑岚岜岵岢岽岬岫岱 岣峁岷峄峒峤峋峥崂崃崧崦崮崤崞崆崛嵘崾崴崽嵬嵛嵯嵝嵫嵋嵊嵩嵴嶂嶙嶝豳嶷巅彳彷徂徇徉後徕徙徜徨徭徵徼衢彡犭犰犴犷犸狃狁狎狍狒狨狯狩狲狴狷猁狳猃狺狻 猗猓猡猊猞猝猕猢猹猥猬猸猱獐獍獗獠獬獯獾"  +  
    93.       " 舛夥飧夤夂饣饧饨饩饪饫饬饴饷饽馀馄馇馊馍馐馑馓馔馕庀庑庋庖庥庠庹庵庾庳赓廒廑廛廨廪膺忄忉忖忏怃忮怄忡忤忾怅怆忪忭忸怙怵怦怛怏怍怩怫怊怿怡恸恹恻恺 恂恪恽悖悚悭悝悃悒悌悛惬悻悱惝惘惆惚悴愠愦愕愣惴愀愎愫慊慵憬憔憧憷懔懵忝隳闩闫闱闳闵闶闼闾阃阄阆阈阊阋阌阍阏阒阕阖阗阙阚丬爿戕氵汔汜汊沣沅沐沔沌 汨汩汴汶沆沩泐泔沭泷泸泱泗沲泠泖泺泫泮沱泓泯泾洹洧洌浃浈洇洄洙洎洫浍洮洵洚浏浒浔洳涑浯涞涠浞涓涔浜浠浼浣渚淇淅淞渎涿淠渑淦淝淙渖涫渌涮渫湮湎湫溲 湟溆湓湔渲渥湄滟溱溘滠漭滢溥溧溽溻溷滗溴滏溏滂"  +  
    94.       " 溟潢潆潇漤漕滹漯漶潋潴漪漉漩澉澍澌潸潲潼潺濑濉澧澹澶濂濡濮濞濠濯瀚瀣瀛瀹瀵灏灞宀宄宕宓宥宸甯骞搴寤寮褰寰蹇謇辶迓迕迥迮迤迩迦迳迨逅逄逋逦逑逍逖逡 逵逶逭逯遄遑遒遐遨遘遢遛暹遴遽邂邈邃邋彐彗彖彘尻咫屐屙孱屣屦羼弪弩弭艴弼鬻屮妁妃妍妩妪妣妗姊妫妞妤姒妲妯姗妾娅娆姝娈姣姘姹娌娉娲娴娑娣娓婀婧婊婕 娼婢婵胬媪媛婷婺媾嫫媲嫒嫔媸嫠嫣嫱嫖嫦嫘嫜嬉嬗嬖嬲嬷孀尕尜孚孥孳孑孓孢驵驷驸驺驿驽骀骁骅骈骊骐骒骓骖骘骛骜骝骟骠骢骣骥骧纟纡纣纥纨纩纭纰纾绀绁绂 绉绋绌绐绔绗绛绠绡绨绫绮绯绱绲缍绶绺绻绾缁缂缃"  +  "缇缈缋 缌缏缑缒缗缙缜缛缟缡缢缣缤缥缦缧缪缫缬缭缯缰缱缲缳缵幺畿巛甾邕玎玑玮玢玟珏珂珑玷玳珀珉珈珥珙顼琊珩珧珞玺珲琏琪瑛琦琥琨琰琮琬琛琚瑁瑜瑗瑕瑙瑷瑭瑾 璜璎璀璁璇璋璞璨璩璐璧瓒璺韪韫韬杌杓杞杈杩枥枇杪杳枘枧杵枨枞枭枋杷杼柰栉柘栊柩枰栌柙枵柚枳柝栀柃枸柢栎柁柽栲栳桠桡桎桢桄桤梃栝桕桦桁桧桀栾桊桉栩 梵梏桴桷梓桫棂楮棼椟椠棹椤棰椋椁楗棣椐楱椹楠楂楝榄楫榀榘楸椴槌榇榈槎榉楦楣楹榛榧榻榫榭槔榱槁槊槟榕槠榍槿樯槭樗樘橥槲橄樾檠橐橛樵檎橹樽樨橘橼檑檐 檩檗檫猷獒殁殂殇殄殒殓殍殚殛殡殪轫轭轱轲轳轵轶"  +  
    95.       " 轸轷轹轺轼轾辁辂辄辇辋辍辎辏辘辚軎戋戗戛戟戢戡戥戤戬臧瓯瓴瓿甏甑甓攴旮旯旰昊昙杲昃昕昀炅曷昝昴昱昶昵耆晟晔晁晏晖晡晗晷暄暌暧暝暾曛曜曦曩贲贳贶贻 贽赀赅赆赈赉赇赍赕赙觇觊觋觌觎觏觐觑牮犟牝牦牯牾牿犄犋犍犏犒挈挲掰搿擘耄毪毳毽毵毹氅氇氆氍氕氘氙氚氡氩氤氪氲攵敕敫牍牒牖爰虢刖肟肜肓肼朊肽肱肫肭 肴肷胧胨胩胪胛胂胄胙胍胗朐胝胫胱胴胭脍脎胲胼朕脒豚脶脞脬脘脲腈腌腓腴腙腚腱腠腩腼腽腭腧塍媵膈膂膑滕膣膪臌朦臊膻臁膦欤欷欹歃歆歙飑飒飓飕飙飚殳彀毂 觳斐齑斓於旆旄旃旌旎旒旖炀炜炖炝炻烀炷炫炱烨烊焐焓焖焯焱"  +  
    96.       " 煳煜煨煅煲煊煸煺熘熳熵熨熠燠燔燧燹爝爨灬焘煦熹戾戽扃扈扉礻祀祆祉祛祜祓祚祢祗祠祯祧祺禅禊禚禧禳忑忐怼恝恚恧恁恙恣悫愆愍慝憩憝懋懑戆肀聿沓泶淼矶矸 砀砉砗砘砑斫砭砜砝砹砺砻砟砼砥砬砣砩硎硭硖硗砦硐硇硌硪碛碓碚碇碜碡碣碲碹碥磔磙磉磬磲礅磴礓礤礞礴龛黹黻黼盱眄眍盹眇眈眚眢眙眭眦眵眸睐睑睇睃睚睨睢 睥睿瞍睽瞀瞌瞑瞟瞠瞰瞵瞽町畀畎畋畈畛畲畹疃罘罡罟詈罨罴罱罹羁罾盍盥蠲钅钆钇钋钊钌钍钏钐钔钗钕钚钛钜钣钤钫钪钭钬钯钰钲钴钶钷钸钹钺钼钽钿铄铈铉铊铋 铌铍铎铐铑铒铕铖铗铙铘铛铞铟铠铢铤铥铧铨铪铩铫铮铯铳铴铵铷铹铼"  +  
    97.       " 铽铿锃锂锆锇锉锊锍锎锏锒锓锔锕锖锘锛锝锞锟锢锪锫锩锬锱锲锴锶锷锸锼锾锿镂锵镄镅镆镉镌镎镏镒镓镔镖镗镘镙镛镞镟镝镡镢镤镥镦镧镨镩镪镫镬镯镱镲镳锺矧 矬雉秕秭秣秫稆嵇稃稂稞稔稹稷穑黏馥穰皈皎皓皙皤瓞瓠甬鸠鸢鸨鸩鸪鸫鸬鸲鸱鸶鸸鸷鸹鸺鸾鹁鹂鹄鹆鹇鹈鹉鹋鹌鹎鹑鹕鹗鹚鹛鹜鹞鹣鹦鹧鹨鹩鹪鹫鹬鹱鹭鹳疒疔疖 疠疝疬疣疳疴疸痄疱疰痃痂痖痍痣痨痦痤痫痧瘃痱痼痿瘐瘀瘅瘌瘗瘊瘥瘘瘕瘙瘛瘼瘢瘠癀瘭瘰瘿瘵癃瘾瘳癍癞癔癜癖癫癯翊竦穸穹窀窆窈窕窦窠窬窨窭窳衤衩衲衽衿 袂裆袷袼裉裢裎裣裥裱褚裼裨裾裰褡褙褓褛褊褴褫褶襁襦疋胥皲皴矜耒"  +  
    98.       " 耔耖耜耠耢耥耦耧耩耨耱耋耵聃聆聍聒聩聱覃顸颀颃颉颌颍颏颔颚颛颞颟颡颢颥颦虍虔虬虮虿虺虼虻蚨蚍蚋蚬蚝蚧蚣蚪蚓蚩蚶蛄蚵蛎蚰蚺蚱蚯蛉蛏蚴蛩蛱蛲蛭蛳蛐蜓 蛞蛴蛟蛘蛑蜃蜇蛸蜈蜊蜍蜉蜣蜻蜞蜥蜮蜚蜾蝈蜴蜱蜩蜷蜿螂蜢蝽蝾蝻蝠蝰蝌蝮螋蝓蝣蝼蝤蝙蝥螓螯螨蟒蟆螈螅螭螗螃螫蟥螬螵螳蟋蟓螽蟑蟀蟊蟛蟪蟠蟮蠖蠓蟾蠊蠛蠡 蠹蠼缶罂罄罅舐竺竽笈笃笄笕笊笫笏筇笸笪笙笮笱笠笥笤笳笾笞筘筚筅筵筌筝筠筮筻筢筲筱箐箦箧箸箬箝箨箅箪箜箢箫箴篑篁篌篝篚篥篦篪簌篾篼簏簖簋簟簪簦簸籁 籀臾舁舂舄臬衄舡舢舣舭舯舨舫舸舻舳舴舾艄艉艋艏艚艟艨衾袅袈裘裟襞羝羟"  +  
    99.       " 羧羯羰羲籼敉粑粝粜粞粢粲粼粽糁糇糌糍糈糅糗糨艮暨羿翎翕翥翡翦翩翮翳糸絷綦綮繇纛麸麴赳趄趔趑趱赧赭豇豉酊酐酎酏酤酢酡酰酩酯酽酾酲酴酹醌醅醐醍醑醢醣 醪醭醮醯醵醴醺豕鹾趸跫踅蹙蹩趵趿趼趺跄跖跗跚跞跎跏跛跆跬跷跸跣跹跻跤踉跽踔踝踟踬踮踣踯踺蹀踹踵踽踱蹉蹁蹂蹑蹒蹊蹰蹶蹼蹯蹴躅躏躔躐躜躞豸貂貊貅貘貔 斛觖觞觚觜觥觫觯訾謦靓雩雳雯霆霁霈霏霎霪霭霰霾龀龃龅龆龇龈龉龊龌黾鼋鼍隹隼隽雎雒瞿雠銎銮鋈錾鍪鏊鎏鐾鑫鱿鲂鲅鲆鲇鲈稣鲋鲎鲐鲑鲒鲔鲕鲚鲛鲞鲟鲠鲡鲢 鲣鲥鲦鲧鲨鲩鲫鲭鲮鲰鲱鲲鲳鲴鲵鲶鲷鲺鲻鲼鲽鳄鳅鳆鳇鳊鳋鳌鳍鳎鳏鳐鳓鳔"  +  "鳕鳗鳘鳙鳜鳝鳟鳢靼鞅鞑鞒鞔鞯鞫鞣鞲鞴骱骰骷鹘骶骺骼髁髀髅髂髋髌髑魅魃魇魉魈魍魑飨餍餮饕饔髟髡髦髯髫髻髭髹鬈鬏鬓鬟鬣麽麾縻麂麇麈麋麒鏖麝麟黛黜黝黠黟黢黩黧黥黪黯鼢鼬鼯鼹鼷鼽鼾齄" ;  
    100.         byte [] array =  new   byte [2];  
    101.         string  return_py =  "" ;  
    102.         for  ( int  i = 0; i < hz.Length; i++)  
    103.         {  
    104.             array = System.Text.Encoding.Default.GetBytes(hz[i].ToString());  
    105.             if  (array[0] < 176)   //.非汉字   
    106.             {  
    107.                 return_py += hz[i];  
    108.             }  
    109.             else   if  (array[0] >= 176 && array[0] <= 215)   //一级汉字   
    110.             {  
    111.                 if  (hz[i].ToString().CompareTo( "匝" ) >= 0)  
    112.                     return_py += "z" ;  
    113.                 else   if  (hz[i].ToString().CompareTo( "压" ) >= 0)  
    114.                     return_py += "y" ;  
    115.                 else   if  (hz[i].ToString().CompareTo( "昔" ) >= 0)  
    116.                     return_py += "x" ;  
    117.                 else   if  (hz[i].ToString().CompareTo( "挖" ) >= 0)  
    118.                     return_py += "w" ;  
    119.                 else   if  (hz[i].ToString().CompareTo( "塌" ) >= 0)  
    120.                     return_py += "t" ;  
    121.                 else   if  (hz[i].ToString().CompareTo( "撒" ) >= 0)  
    122.                     return_py += "s" ;  
    123.                 else   if  (hz[i].ToString().CompareTo( "然" ) >= 0)  
    124.                     return_py += "r" ;  
    125.                 else   if  (hz[i].ToString().CompareTo( "期" ) >= 0)  
    126.                     return_py += "q" ;  
    127.                 else   if  (hz[i].ToString().CompareTo( "啪" ) >= 0)  
    128.                     return_py += "p" ;  
    129.                 else   if  (hz[i].ToString().CompareTo( "哦" ) >= 0)  
    130.                     return_py += "o" ;  
    131.                 else   if  (hz[i].ToString().CompareTo( "拿" ) >= 0)  
    132.                     return_py += "n" ;  
    133.                 else   if  (hz[i].ToString().CompareTo( "妈" ) >= 0)  
    134.                     return_py += "m" ;  
    135.                 else   if  (hz[i].ToString().CompareTo( "垃" ) >= 0)  
    136.                     return_py += "l" ;  
    137.                 else   if  (hz[i].ToString().CompareTo( "喀" ) >= 0)  
    138.                     return_py += "k" ;  
    139.                 else   if  (hz[i].ToString().CompareTo( "击" ) >= 0)  
    140.                     return_py += "j" ;  
    141.                 else   if  (hz[i].ToString().CompareTo( "哈" ) >= 0)  
    142.                     return_py += "h" ;  
    143.                 else   if  (hz[i].ToString().CompareTo( "噶" ) >= 0)  
    144.                     return_py += "g" ;  
    145.                 else   if  (hz[i].ToString().CompareTo( "发" ) >= 0)  
    146.                     return_py += "f" ;  
    147.                 else   if  (hz[i].ToString().CompareTo( "蛾" ) >= 0)  
    148.                     return_py += "e" ;  
    149.                 else   if  (hz[i].ToString().CompareTo( "搭" ) >= 0)  
    150.                     return_py += "d" ;  
    151.                 else   if  (hz[i].ToString().CompareTo( "擦" ) >= 0)  
    152.                     return_py += "c" ;  
    153.                 else   if  (hz[i].ToString().CompareTo( "芭" ) >= 0)  
    154.                     return_py += "b" ;  
    155.                 else   if  (hz[i].ToString().CompareTo( "啊" ) >= 0)  
    156.                     return_py += "a" ;  
    157.             }  
    158.             else   if  (array[0] >= 215)     //二级汉字   
    159.             {  
    160.                 return_py += ls_second_eng.Substring(ls_second_ch.IndexOf(hz[i].ToString(), 0), 1);  
    161.             }  
    162.         }  
    163.         return  return_py.ToLower();  
    164.     }  
    165.     /// <summary>   
    166.     /// 把汉字转换成拼音(全拼)   
    167.     /// </summary>   
    168.     /// <param name="hzString">汉字字符串</param>   
    169.     /// <returns>转换后的拼音(全拼)字符串</returns>   
    170.     public   static   string  GetAllPYLetters( string  hzString)  
    171.     {  
    172.         // 匹配中文字符   
    173.         Regex regex = new  Regex( "^[/u4e00-/u9fa5]$" );  
    174.         byte [] array =  new   byte [2];  
    175.         string  pyString =  "" ;  
    176.         int  chrAsc = 0;  
    177.         int  i1 = 0;  
    178.         int  i2 = 0;  
    179.         char [] noWChar = hzString.ToCharArray();  
    180.         for  ( int  j = 0; j < noWChar.Length; j++)  
    181.         {  
    182.             // 中文字符   
    183.             if  (regex.IsMatch(noWChar[j].ToString()))  
    184.             {  
    185.                 array = System.Text.Encoding.Default.GetBytes(noWChar[j].ToString());  
    186.                 i1 = (short )(array[0]);  
    187.                 i2 = (short )(array[1]);  
    188.                 chrAsc = i1 * 256 + i2 - 65536;  
    189.                 if  (chrAsc > 0 && chrAsc < 160)  
    190.                 {  
    191.                     pyString += noWChar[j];  
    192.                 }  
    193.                 else   
    194.                 {  
    195.                     // 修正部分文字   
    196.                     if  (chrAsc == -9254)   // 修正“圳”字   
    197.                         pyString += "Zhen" ;  
    198.                     else   
    199.                     {  
    200.                         for  ( int  i = (pyValue.Length - 1); i >= 0; i--)  
    201.                         {  
    202.                             if  (pyValue[i] <= chrAsc)  
    203.                             {  
    204.                                 pyString += pyName[i];  
    205.                                 break ;  
    206.                             }  
    207.                         }  
    208.                     }  
    209.                 }  
    210.             }  
    211.             // 非中文字符   
    212.             else   
    213.             {  
    214.                 pyString += noWChar[j].ToString();  
    215.             }  
    216.         }  
    217.         return  pyString;  
    218.     } 
  • 相关阅读:
    #include <boost/scoped_ptr.hpp>
    #include <boost/function.hpp>
    #include <boost/bind.hpp>
    8.4散列表查找
    #include <boost/array.hpp>
    异常
    lambda
    #include <amp.h>
    #include <bitset>
    #include <hash_set>
  • 原文地址:https://www.cnblogs.com/xyzlmn/p/3168351.html
Copyright © 2011-2022 走看看