java.util.collections import; import java.util.iterator; java.util.linkedhashmap import; java.util.map import; / ** * 将汉字转化为全拼 */ public class cntospell1 {private static map <string, integer> spellmap = null; // 存放生僻字和其拼音的 개인 정적 맵 <문자, 문자열> uncommonwordsmap = null; static {if (spellmap == null) {spellmap = collections.synchronizedMap (new LinkedHashMap <string, integer> (396)); uncommonwordsmap = collections.synchronizedMap (new LinkedHashMap <문자, 문자열> (200)); } 초기화 (); inituncommonwords (); } private cntospell1 () {} / ** * 初始化 * / private static void initialize () {spellmap.put ( " 'a", -20319); SpellMap.put ( " 'ai", -20317); SpellMap.put ( " 'an", -20304); SpellMap.put ( " 'ang", -20295); SpellMap.put ( " 'ao", -20292); SpellMap.put ( "BA", -20283); SpellMap.put ( "Bai", -20265); SpellMap.put ( "Ban", -20257); SpellMap.put ( "bang", -20242); SpellMap.put ( "Bao", -20230); SpellMap.put ( "Bei", -20051); SpellMap.put ( "Ben", -20036); SpellMap.put ( "Beng", -20032); SpellMap.put ( "bi", -20026); SpellMap.put ( "Bian", -20002); SpellMap.put ( "Biao", -19990); SpellMap.put ( "bie", -19986); SpellMap.put ( "bin", -19982); SpellMap.put ( "Bing", -19976); SpellMap.put ( "Bo", -19805); SpellMap.put ( "bu", -19784); SpellMap.put ( "CA", -19775); SpellMap.put ( "Cai", -19774); SpellMap.put ( "can", -19763); SpellMap.put ( "cang", -19756); SpellMap.put ( "Cao", -19751); SpellMap.put ( "CE", -19746); SpellMap.put ( "Ceng", -19741); SpellMap.put ( "Cha", -19739); SpellMap.put ( "Chai", -19728); SpellMap.put ( "Chan", -19725); SpellMap.put ( "Chang", -19715); SpellMap.put ( "Chao", -19540); SpellMap.put ( "Che", -19531); SpellMap.put ( "Chen", -19525); SpellMap.put ( "Cheng", -19515); SpellMap.put ( "Chi", -19500); SpellMap.put ( "chong", -19484); SpellMap.put ( "chou", -19479); SpellMap.put ( "chu", -19467); SpellMap.put ( "Chuai", -19289); SpellMap.put ( "Chuan", -19288); SpellMap.put ( "Chuang", -19281); SpellMap.put ( "chui", -19275); SpellMap.put ( "Chun", -19270); SpellMap.put ( "chuo", -19263); SpellMap.put ( "CI", -19261); SpellMap.put ( "Cong", -19249); SpellMap.put ( "COU", -19243); SpellMap.put ( "Cu", -19242); SpellMap.put ( "Cuan", -19238); SpellMap.put ( "Cui", -19235); SpellMap.put ( "CUN", -19227); SpellMap.put ( "Cuo", -19224); SpellMap.put ( "da", -19218); SpellMap.put ( "Dai", -19212); SpellMap.put ( "dan", -19038); SpellMap.put ( "dang", -19023); SpellMap.put ( "dao", -19018); SpellMap.put ( "de", -19006); SpellMap.put ( "Deng", -19003); SpellMap.put ( "di", -18996); SpellMap.put ( "Dian", -18977); SpellMap.put ( "Diao", -18961); SpellMap.put ( "다이", -18952); SpellMap.put ( "Ding", -18783); SpellMap.put ( "Diu", -18774); SpellMap.put ( "Dong", -18773); SpellMap.put ( "Dou", -18763); SpellMap.put ( "du", -18756); SpellMap.put ( "duan", -18741); SpellMap.put ( "dui", -18735); SpellMap.put ( "Dun", -18731); SpellMap.put ( "듀오", -18722); SpellMap.put ( " 'e", -18710); SpellMap.put ( " 'en", -18697); SpellMap.put ( " 'er", -18696); SpellMap.put ( "fa", -18526); SpellMap.put ( "fan", -18518); SpellMap.put ( "Fang", -18501); SpellMap.put ( "fei", -18490); SpellMap.put ( "Fen", -18478); SpellMap.put ( "feng", -18463); SpellMap.put ( "fo", -18448); SpellMap.put ( "fou", -18447); SpellMap.put ( "fu", -18446); SpellMap.put ( "ga", -18239); SpellMap.put ( "gai", -18237); SpellMap.put ( "Gan", -18231); SpellMap.put ( "갱", -18220); SpellMap.put ( "gao", -18211); SpellMap.put ( "GE", -18201); SpellMap.put ( "gei", -18184); SpellMap.put ( "Gen", -18183); SpellMap.put ( "Geng", -18181); SpellMap.put ( "gong", -18012); SpellMap.put ( "gou", -17997); SpellMap.put ( "GU", -17988); SpellMap.put ( "Gua", -17970); SpellMap.put ( "Guai", -17964); SpellMap.put ( "Guan", -17961); SpellMap.put ( "Guang", -17950); SpellMap.put ( "GUI", -17947); SpellMap.put ( "Gun", -17931); SpellMap.put ( "Guo", -17928); SpellMap.put ( "ha", -17922); SpellMap.put ( "Hai", -17759); SpellMap.put ( "Han", -17752); SpellMap.put ( "행", -17733); SpellMap.put ( "Hao", -17730); SpellMap.put ( "HE", -17721); SpellMap.put ( "hei", -17703); SpellMap.put ( "Hen", -17701); SpellMap.put ( "heng", -17697); SpellMap.put ( "Hong", -17692); SpellMap.put ( "hou", -17683); SpellMap.put ( "hu", -17676); SpellMap.put ( "hua", -17496); SpellMap.put ( "Huai", -17487); SpellMap.put ( "Huan", -17482); SpellMap.put ( "Huang", -17468); SpellMap.put ( "hui", -17454); SpellMap.put ( "Hun", -17433); SpellMap.put ( "Huo", -17427); SpellMap.put ( "ji", -17417); SpellMap.put ( "jia", -17202); SpellMap.put ( "Jian", -17185); SpellMap.put ( "Jiang", -16983); SpellMap.put ( "Jiao", -16970); SpellMap.put ( "jie", -16942); SpellMap.put ( "Jin", -16915); SpellMap.put ( "Jing", -16733); SpellMap.put ( "jiong", -16708); SpellMap.put ( "jiu", -16706); SpellMap.put ( "ju", -16689); SpellMap.put ( "Juan", -16664); SpellMap.put ( "Jue", -16657); SpellMap.put ( "Jun", -16647); SpellMap.put ( "ka", -16474); SpellMap.put ( "Kai", -16470); SpellMap.put ( "Kan", -16465); SpellMap.put ( "Kang", -16459); SpellMap.put ( "Kao", -16452); SpellMap.put ( "Ke", -16448); SpellMap.put ( "Ken", -16433); SpellMap.put ( "Keng", -16429); SpellMap.put ( "Kong", -16427); SpellMap.put ( "kou", -16423); SpellMap.put ( "ku", -16419); SpellMap.put ( "kua", -16412); SpellMap.put ( "Kuai", -16407); SpellMap.put ( "Kuan", -16403); SpellMap.put ( "Kuang", -16401); SpellMap.put ( "kui", -16393); SpellMap.put ( "Kun", -16220); SpellMap.put ( "Kuo", -16216); SpellMap.put ( "la", -16212); SpellMap.put ( "lai", -16205); SpellMap.put ( "lan", -16202); SpellMap.put ( "Lang", -16187); SpellMap.put ( "lao", -16180); SpellMap.put ( "le", -16171); SpellMap.put ( "lei", -16169); SpellMap.put ( "leng", -16158); SpellMap.put ( "li", -16155); SpellMap.put ( "lia", -15959); SpellMap.put ( "Lian", -15958); SpellMap.put ( "Liang", -15944); SpellMap.put ( "liao", -15933); SpellMap.put ( "lie", -15920); SpellMap.put ( "Lin", -15915); SpellMap.put ( "Ling", -15903); SpellMap.put ( "liu", -15889); SpellMap.put ( "long", -15878); SpellMap.put ( "lou", -15707); SpellMap.put ( "lu", -15701); SpellMap.put ( "LV", -15681); SpellMap.put ( "Luan", -15667); SpellMap.put ( "lue", -15661); SpellMap.put ( "LUN", -15659); SpellMap.put ( "Luo", -15652); SpellMap.put ( "ma", -15640); SpellMap.put ( "Mai", -15631); SpellMap.put ( "man", -15625); SpellMap.put ( "Mang", -15454); SpellMap.put ( "Mao", -15448); SpellMap.put ( "me", -15436); SpellMap.put ( "Mei", -15435); SpellMap.put ( "men", -15419); SpellMap.put ( "meng", -15416); SpellMap.put ( "mi", -15408); SpellMap.put ( "Mian", -15394); SpellMap.put ( "Miao", -15385); SpellMap.put ( "mie", -15377); SpellMap.put ( "Min", -15375); SpellMap.put ( "Ming", -15369); SpellMap.put ( "miu", -15363); SpellMap.put ( "mo", -15362); SpellMap.put ( "mou", -15183); SpellMap.put ( "mu", -15180); SpellMap.put ( "NA", -15165); SpellMap.put ( "Nai", -15158); SpellMap.put ( "Nan", -15153); SpellMap.put ( "Nang", -15150); SpellMap.put ( "NAO", -15149); SpellMap.put ( "NE", -15144); SpellMap.put ( "Nei", -15143); SpellMap.put ( "Nen", -15141); SpellMap.put ( "neng", -15140); SpellMap.put ( "ni", -15139); SpellMap.put ( "Nian", -15128); SpellMap.put ( "Niang", -15121); SpellMap.put ( "niao", -15119); SpellMap.put ( "nie", -15117); SpellMap.put ( "Nin", -15110); SpellMap.put ( "Ning", -15109); SpellMap.put ( "niu", -14941); SpellMap.put ( "Nong", -14937); SpellMap.put ( "nu", -14933); SpellMap.put ( "NV", -14930); SpellMap.put ( "Nuan", -14929); SpellMap.put ( "nue", -14928); SpellMap.put ( "nuo", -14926); SpellMap.put ( " 'O", -14922); SpellMap.put ( " 'OU", -14921); SpellMap.put ( "PA", -14914); SpellMap.put ( "Pai", -14908); SpellMap.put ( "Pan", -14902); SpellMap.put ( "Pang", -14894); SpellMap.put ( "Pao", -14889); SpellMap.put ( "PEI", -14882); SpellMap.put ( "PEN", -14873); SpellMap.put ( "Peng", -14871); SpellMap.put ( "pi", -14857); SpellMap.put ( "Pian", -14678); SpellMap.put ( "Piao", -14674); SpellMap.put ( "파이", -14670); SpellMap.put ( "핀", -14668); SpellMap.put ( "Ping", -14663); SpellMap.put ( "PO", -14654); SpellMap.put ( "pu", -14645); SpellMap.put ( "Qi", -14630); SpellMap.put ( "QIA", -14594); SpellMap.put ( "Qian", -14429); SpellMap.put ( "Qiang", -14407); SpellMap.put ( "Qiao", -14399); SpellMap.put ( "Qie", -14384); SpellMap.put ( "Qin", -14379); SpellMap.put ( "Qing", -14368); SpellMap.put ( "QIONG", -14355); SpellMap.put ( "Qiu", -14353); SpellMap.put ( "qu", -14345); SpellMap.put ( "Quan", -14170); SpellMap.put ( "que", -14159); SpellMap.put ( "Qun", -14151); SpellMap.put ( "Ran", -14149); SpellMap.put ( "rang", -14145); SpellMap.put ( "Rao", -14140); SpellMap.put ( "re", -14137); SpellMap.put ( "ren", -14135); SpellMap.put ( "reng", -14125); SpellMap.put ( "ri", -14123); SpellMap.put ( "Rong", -14122); SpellMap.put ( "rou", -14112); SpellMap.put ( "ru", -14109); SpellMap.put ( "Ruan", -14099); SpellMap.put ( "rui", -14097); SpellMap.put ( "run", -14094); SpellMap.put ( "ruo", -14092); SpellMap.put ( "SA", -14090); SpellMap.put ( "Sai", -14087); SpellMap.put ( "San", -14083); SpellMap.put ( "Sang", -13917); SpellMap.put ( "Sao", -13914); SpellMap.put ( "SE", -13910); SpellMap.put ( "sen", -13907); SpellMap.put ( "Seng", -13906); SpellMap.put ( "sha", -13905); SpellMap.put ( "Shai", -13896); SpellMap.put ( "Shan", -13894); SpellMap.put ( "Shang", -13878); SpellMap.put ( "Shao", -13870); SpellMap.put ( "She", -13859); SpellMap.put ( "Shen", -13847); SpellMap.put ( "sheng", -13831); SpellMap.put ( "Shi", -13658); SpellMap.put ( "shou", -13611); SpellMap.put ( "shu", -13601); SpellMap.put ( "shua", -13406); SpellMap.put ( "Shuai", -13404); SpellMap.put ( "Shuan", -13400); SpellMap.put ( "Shuang", -13398); SpellMap.put ( "shui", -13395); SpellMap.put ( "Shun", -13391); SpellMap.put ( "shuo", -13387); SpellMap.put ( "si", -13383); SpellMap.put ( "노래", -13367); SpellMap.put ( "sou", -13359); SpellMap.put ( "su", -13356); SpellMap.put ( "Suan", -13343); SpellMap.put ( "Sui", -13340); SpellMap.put ( "Sun", -13329); SpellMap.put ( "Suo", -13326); SpellMap.put ( "TA", -13318); SpellMap.put ( "tai", -13147); SpellMap.put ( "tan", -13138); SpellMap.put ( "tang", -13120); SpellMap.put ( "Tao", -13107); SpellMap.put ( "te", -13096); SpellMap.put ( "Teng", -13095); SpellMap.put ( "ti", -13091); SpellMap.put ( "Tian", -13076); SpellMap.put ( "Tiao", -13068); SpellMap.put ( "tie", -13063); SpellMap.put ( "Ting", -13060); SpellMap.put ( "Tong", -12888); SpellMap.put ( "tou", -12875); SpellMap.put ( "tu", -12871); SpellMap.put ( "Tuan", -12860); SpellMap.put ( "tui", -12858); SpellMap.put ( "Tun", -12852); SpellMap.put ( "tuo", -12849); SpellMap.put ( "WA", -12838); SpellMap.put ( "Wai", -12831); SpellMap.put ( "wan", -12829); SpellMap.put ( "Wang", -12812); SpellMap.put ( "Wei", -12802); SpellMap.put ( "wen", -12607); SpellMap.put ( "weng", -12597); SpellMap.put ( "wo", -12594); SpellMap.put ( "wu", -12585); SpellMap.put ( "xi", -12556); SpellMap.put ( "Xia", -12359); SpellMap.put ( "Xian", -12346); SpellMap.put ( "Xiang", -12320); SpellMap.put ( "Xiao", -12300); SpellMap.put ( "Xie", -12120); SpellMap.put ( "Xin", -12099); SpellMap.put ( "Xing", -12089); SpellMap.put ( "Xiong", -12074); SpellMap.put ( "xiu", -12067); SpellMap.put ( "xu", -12058); SpellMap.put ( "Xuan", -12039); SpellMap.put ( "Xue", -11867); SpellMap.put ( "Xun", -11861); SpellMap.put ( "YA", -11847); SpellMap.put ( "Yan", -11831); SpellMap.put ( "Yang", -11798); SpellMap.put ( "Yao", -11781); SpellMap.put ( "Ye", -11604); SpellMap.put ( "yi", -11589); SpellMap.put ( "Yin", -11536); SpellMap.put ( "Ying", -11358); SpellMap.put ( "Yo", -11340); SpellMap.put ( "Yong", -11339); SpellMap.put ( "You", -11324); SpellMap.put ( "Yu", -11303); SpellMap.put ( "Yuan", -11097); SpellMap.put ( "yue", -11077); SpellMap.put ( "Yun", -11067); SpellMap.put ( "Za", -11055); SpellMap.put ( "Zai", -11052); SpellMap.put ( "Zan", -11045); SpellMap.put ( "Zang", -11041); SpellMap.put ( "Zao", -11038); SpellMap.put ( "Ze", -11024); SpellMap.put ( "Zei", -11020); SpellMap.put ( "Zen", -11019); SpellMap.put ( "Zeng", -11018); SpellMap.put ( "zha", -11014); SpellMap.put ( "Zhai", -10838); SpellMap.put ( "Zhan", -10832); SpellMap.put ( "Zhang", -10815); SpellMap.put ( "Zhao", -10800); SpellMap.put ( "zhe", -10790); SpellMap.put ( "Zhen", -10780); SpellMap.put ( "Zheng", -10764); SpellMap.put ( "Zhi", -10587); SpellMap.put ( "Zhong", -10544); SpellMap.put ( "Zhou", -10533); SpellMap.put ( "Zhu", -10519); SpellMap.put ( "Zhua", -10331); SpellMap.put ( "Zhuai", -10329); SpellMap.put ( "Zhuan", -10328); SpellMap.put ( "Zhuang", -10322); SpellMap.put ( "Zhui", -10315); SpellMap.put ( "Zhun", -10309); SpellMap.put ( "Zhuo", -10307); SpellMap.put ( "Zi", -10296); SpellMap.put ( "Zong", -10281); SpellMap.put ( "Zou", -10274); SpellMap.put ( "Zu", -10270); SpellMap.put ( "Zuan", -10262); SpellMap.put ( "Zui", -10260); SpellMap.put ( "Zun", -10256); SpellMap.put ( "Zuo", -10254); } /** * * * @param cnword 生僻字 * @param spell 生僻字的拼音, 如果拼音以 a, o, e 开头, 请将开头分别改为 'a,'o, 'e, 如 :安 ( 'an) */ public static void putuncommonword (char cnword, string spell) {uncommonwordsmap.put (cnword, spell); } / ** * * * / private static void inituncommonwords () {putuncommonword ( '', "ao"); putuncommonword ( '灞', "ba"); putuncommonword ( '', "벤"); putuncommonword ( '', "biao"); putuncommonword ( '', "biao"); putuncommonword ( '杈', "cha"); putuncommonword ( '', "Chen"); putuncommonword ( '', "Cheng"); putuncommonword ( '魑', "chi"); putuncommonword ( '', "chong"); putuncommonword ( '', "chong"); putuncommonword ( '', "cu"); putuncommonword ( '毳', "cui"); putuncommonword ( '', "fang"); putuncommonword ( '沣', "feng"); putuncommonword ( '', "gou"); putuncommonword ( '焓', "han"); putuncommonword ( '', "Han"); putuncommonword ( '晗', "han"); putuncommonword ( '', "Han"); putuncommonword ( '翮', "He"); putuncommonword ( '', "He"); putuncommonword ( '', "huan"); putuncommonword ( '', "hui"); putuncommonword ( '', "jie"); putuncommonword ( '', "Jing"); putuncommonword ( '', "Jing"); putuncommonword ( '', "Jing"); putuncommonword ( '', "Kun"); putuncommonword ( '琨', "kun"); putuncommonword ( '', "Kun"); putuncommonword ( '骊', "li"); putuncommonword ( '鎏', "liu"); putuncommonword ( '', "man"); putuncommonword ( '', "mei"); putuncommonword ( '淼', "miao"); putuncommonword ( '', "nan"); putuncommonword ( '', "nan"); putuncommonword ( '甯', "ning"); putuncommonword ( '', "ning"); putuncommonword ( '', "pa"); putuncommonword ( '', "pi"); putuncommonword ( '', "Qian"); putuncommonword ( '', "qin"); putuncommonword ( '', "Qing"); putuncommonword ( '', "Qing"); putuncommonword ( '', "Qing"); putuncommonword ( '', "Qing"); putuncommonword ( '', "Qing"); putuncommonword ( '悫', "que"); putuncommonword ( '', "que"); putuncommonword ( '', "rong"); putuncommonword ( '', "shen"); putuncommonword ( '', "shen"); putuncommonword ( '', "shen"); putuncommonword ( '', "sheng"); putuncommonword ( '', "sheng"); putuncommonword ( '晟', "sheng"); putuncommonword ( '', "sheng"); putuncommonword ( '眚', "sheng"); putuncommonword ( '', "sheng"); putuncommonword ( '', "sheng"); putuncommonword ( '', "sheng"); putuncommonword ( '', "sheng"); putuncommonword ( '', "shi"); putuncommonword ( '', "su"); putuncommonword ( '', "tao"); putuncommonword ( '', "tian"); putuncommonword ( '仝', "tong"); putuncommonword ( '', "wei"); putuncommonword ( '炜', "wei"); putuncommonword ( '玮', "wei"); putuncommonword ( '', "wu"); putuncommonword ( '邬', "wu"); putuncommonword ( '', "xi"); putuncommonword ( '', "Xian"); putuncommonword ( '', "Xiao"); putuncommonword ( '', "Xiao"); putuncommonword ( '筱', "xiao"); putuncommonword ( '勰', "xie"); putuncommonword ( '忻', "xin"); putuncommonword ( '庥', "xiu"); putuncommonword ( '', "xu"); putuncommonword ( '', "xu"); putuncommonword ( '', "xu"); putuncommonword ( '', "xuan"); putuncommonword ( '煊', "xuan"); putuncommonword ( '', "xuan"); putuncommonword ( '', "xuan"); putuncommonword ( '暄', "xuan"); putuncommonword ( '娅', "ya"); putuncommonword ( '琰', "yan"); putuncommonword ( '妍', "yan"); putuncommonword ( '焱', "yan"); putuncommonword ( '', "Yang"); putuncommonword ( '', "Yang"); putuncommonword ( '', "Yang"); putuncommonword ( '', "yao"); putuncommonword ( '', "yao"); putuncommonword ( '怡', "yi"); putuncommonword ( '', "yi"); putuncommonword ( '', "yi"); putuncommonword ( '', "yi"); putuncommonword ( '瑛', "ying"); putuncommonword ( '', "ying"); putuncommonword ( '', "ying"); putuncommonword ( '', "ying"); putuncommonword ( '滢', "ying"); putuncommonword ( '', "ying"); putuncommonword ( '莜', "you"); putuncommonword ( '昱', "yu"); putuncommonword ( '', "yun"); putuncommonword ( '', "zhe"); putuncommonword ( '', "zhe"); putuncommonword ( '', "zhi"); } /**** ascii. * @param cn am * @return 汉字对应的 ascii, 错误时返回 0 */ public static int getcnascii (char cn) {byte [] bytes = (string.valueof (cn)). getBytes (); if (bytes == null || bytes.length == 0 || bytes.length> 2) {// 错误 return 0; } if (bytes.length == 1) {// 英文字符 return bytes [0]; } if (bytes.length == 2) {// int hightbyte = 256 + bytes [0]; int lowbyte = 256 + 바이트 [1]; 반환 (256 * Hightbyte + Lowbyte) -256 * 256; // 返回 ascii} 반환 0; // 错误} /** * 根据 ascii 码到 spellmap 中查找对应的拼音 * @param ascii ascii * @return ascii 对应的拼音, 如果 ascii 对应的字符为单字符, 则返回对应的单字符, 如果不是单 如果不是单Spellmap ap, 则返回空字符串 ( ""), */ public static string getSpellbyascii (int ascii) {if (ascii> 0 && ascii <160) {// 单字符 retring string. value -of ((char) ascii); } if (ascii <-20319 || ascii> -10247) {// 不知道的字符 return ""; } 문자열 주문 = null; // 키 정수 asciirang; // 값 문자열 spellprevious = null; // 用来保存上次轮循环的 key int asciirangprevious = -20319; // (iterator it = spellmap.keyset (). iterator (); it.hasnext ();) {spell = (string) it.next (); // 拼音 asciirang = spellmap.get (주문); // 拼音的 ascii if (asciirang! = null) {if (ascii> = asciirangprevious && ascii <asciirang) {// 区间找到, return (spellprevious == null)? 주문 : Spellprevious; } else {spellprevious = 주문; asciirangprevious = asciirang; } } } 반품 ""; } /** * *, 是汉字则转化为对应的拼音或拼音首字母, 是汉字则转化为对应的拼音或拼音首字母 * @param cnstr 要获取全拼或首拼的字符串 * @param ONLEFIRSTSPELL st st, 为 true 时, 只获取首拼 只获取首拼, 为 false 时, 获取全拼 * @return 문자열 cnstr 的全拼或首拼, 如果 cnstr 为 null 时, 返回 "" */ public static string getSpell (String Cnstr, Boolean OnlyFirstSpell) {if (cnstr == null) {return ""; } char [] chars = cnstr.trim (). tochararray (); StringBuffer sb = new StringBuffer (); for (int i = 0, len = chars.length; i <len; i ++) {int ascii = getcnascii (chars [i]); if (ascii == 0) {// 如果获取汉字的 ascii 出错, 则不进行转换 sb.append (chars [i]); } else {문자열 spell = getSpellbyAscii (ascii); // 根据 ascii 取拼音 if (spell == null || spell.length () == 0) {// 如果根据 ascii 取拼音没取到, 则到生僻字 map spell = uncommonwordsmap.get (chars [chars 나]); } if (spell == null || spell.length () == 0) {// 如果没有取到对应的拼音, 则不做转换, spell = uncommonwordsmap.get (chars [i]); } else {if (OnlyFirstSpell) {SB.Append (Spell.startSwith ( " '")? Spell.SubString (1, 2) : Spell.Substring (0, 1)); } else {sb.append (주문); }}}}} // return sb.toString ()에 대한 끝; } public static void main (string [] args) {String [] s = { "获取汉字全拼和首拼测试", "이것은 테스트입니다", "a, b; c [d]", "标,"标, "点。 "," "", 特殊符号・¥%—-- …… ","繁体字 : 西安 : ","西安 ","山 "}; for (int i = 0; i <s.length; i ++) {long l1 = system.currenttimeMillis (); System.out.println (s [i] + "的全拼 :" + getspell (s [i], false)); System.out.println (s [i] + "的首拼 :" + getspell (s [i], true)); System.out.println ( "获取全拼和首拼 共 共"+(System.CurrentTimeMillis () -L1)+"毫秒/n"); }}}