输入汉字自动转为拼音(jsp实现方式)
输入汉字,点击“提交”按钮,所输入汉字的拼音就会自动输入出来,该实现方式是在互联网上找到的,但是我做了一些修改,使其用起来更加明了 。
如果有问题,请与我联系:txyhl@126.com
<%...@ page language="java" import="java.util.*" contentType="text/html; charset=GBK" %>
<%...!
Hashtable ht=new Hashtable(10);
String g(Integer n){
int num=n.intValue();
if(num>0&&num<160){
return String.valueOf((char)num);
}
else if(num<-20319||num>-10247){
return "";
}
else{
if(ht.size()==0){b();}
while(!ht.containsKey(Integer.toString(num)))num--;
return ht.get(Integer.toString(num)).toString();
}
}
String c(String str){
char[] hz=str.toCharArray();
int len=str.length();
int p,q;
String ret="";
for(int i=0;i<len;i++){
p=(int)hz[i];
if(p>160){
q=(int)hz[++i];
p=p*256+q-65536;
}
ret+=g(new Integer(p));
ret=ret+"<b>"+String.valueOf(p)+"</b><br>";
}
return ret;
}
void b(){
ht.put("-20319","a");
ht.put("-20317","ai");
ht.put("-20304","an");
ht.put("-20295","ang");
ht.put("-20292","ao");
ht.put("-20283","ba");
ht.put("-20265","bai");
ht.put("-20257","ban");
ht.put("-20242","bang");
ht.put("-20230","bao");
ht.put("-20051","bei");
ht.put("-20036","ben");
ht.put("-20032","beng");
ht.put("-20026","bi");
ht.put("-20002","bian");
ht.put("-19990","biao");
ht.put("-19986","bie");
ht.put("-19982","bin");
ht.put("-19976","bing");
ht.put("-19805","bo");
ht.put("-19784","bu");
ht.put("-19775","ca");
ht.put("-19774","cai");
ht.put("-19763","can");
ht.put("-19756","cang");
ht.put("-19751","cao");
ht.put("-19746","ce");
ht.put("-19741","ceng");
ht.put("-19739","cha");
ht.put("-19728","chai");
ht.put("-19725","chan");
ht.put("-19715","chang");
ht.put("-19540","chao");
ht.put("-19531","che");
ht.put("-19525","chen");
ht.put("-19515","cheng");
ht.put("-19500","chi");
ht.put("-19484","chong");
ht.put("-19479","chou");
ht.put("-19467","chu");
ht.put("-19289","chuai");
ht.put("-19288","chuan");
ht.put("-19281","chuang");
ht.put("-19275","chui");
ht.put("-19270","chun");
ht.put("-19263","chuo");
ht.put("-19261","ci");
ht.put("-19249","cong");
ht.put("-19243","cou");
ht.put("-19242","cu");
ht.put("-19238","cuan");
ht.put("-19235","cui");
ht.put("-19227","cun");
ht.put("-19224","cuo");
ht.put("-19218","da");
ht.put("-19212","dai");
ht.put("-19038","dan");
ht.put("-19023","dang");
ht.put("-19018","dao");
ht.put("-19006","de");
ht.put("-19003","deng");
ht.put("-18996","di");
ht.put("-18977","dian");
ht.put("-18961","diao");
ht.put("-18952","die");
ht.put("-18783","ding");
ht.put("-18774","diu");
ht.put("-18773","dong");
ht.put("-18763","dou");
ht.put("-18756","du");
ht.put("-18741","duan");
ht.put("-18735","dui");
ht.put("-18731","dun");
ht.put("-18722","duo");
ht.put("-18710","e");
ht.put("-18697","en");
ht.put("-18696","er");
ht.put("-18526","fa");
ht.put("-18518","fan");
ht.put("-18501","fang");
ht.put("-18490","fei");
ht.put("-18478","fen");
ht.put("-18463","feng");
ht.put("-18448","fo");
ht.put("-18447","fou");
ht.put("-18446","fu");
ht.put("-18239","ga");
ht.put("-18237","gai");
ht.put("-18231","gan");
ht.put("-18220","gang");
ht.put("-18211","gao");
ht.put("-18201","ge");
ht.put("-18184","gei");
ht.put("-18183","gen");
ht.put("-18181","geng");
ht.put("-18012","gong");
ht.put("-17997","gou");
ht.put("-17988","gu");
ht.put("-17970","gua");
ht.put("-17964","guai");
ht.put("-17961","guan");
ht.put("-17950","guang");
ht.put("-17947","gui");
ht.put("-17931","gun");
ht.put("-17928","guo");
ht.put("-17922","ha");
ht.put("-17759","hai");
ht.put("-17752","han");
ht.put("-17733","hang");
ht.put("-17730","hao");
ht.put("-17721","he");
ht.put("-17703","hei");
ht.put("-17701","hen");
ht.put("-17697","heng");
ht.put("-17692","hong");
ht.put("-17683","hou");
ht.put("-17676","hu");
ht.put("-17496","hua");
ht.put("-17487","huai");
ht.put("-17482","huan");
ht.put("-17468","huang");
ht.put("-17454","hui");
ht.put("-17433","hun");
ht.put("-17427","huo");
ht.put("-17417","ji");
ht.put("-17202","jia");
ht.put("-17185","jian");
ht.put("-16983","jiang");
ht.put("-16970","jiao");
ht.put("-16942","jie");
ht.put("-16915","jin");
ht.put("-16733","jing");
ht.put("-16708","jiong");
ht.put("-16706","jiu");
ht.put("-16689","ju");
ht.put("-16664","juan");
ht.put("-16657","jue");
ht.put("-16647","jun");
ht.put("-16474","ka");
ht.put("-16470","kai");
ht.put("-16465","kan");
ht.put("-16459","kang");
ht.put("-16452","kao");
ht.put("-16448","ke");
ht.put("-16433","ken");
ht.put("-16429","keng");
ht.put("-16427","kong");
ht.put("-16423","kou");
ht.put("-16419","ku");
ht.put("-16412","kua");
ht.put("-16407","kuai");
ht.put("-16403","kuan");
ht.put("-16401","kuang");
ht.put("-16393","kui");
ht.put("-16220","kun");
ht.put("-16216","kuo");
ht.put("-16212","la");
ht.put("-16205","lai");
ht.put("-16202","lan");
ht.put("-16187","lang");
ht.put("-16180","lao");
ht.put("-16171","le");
ht.put("-16169","lei");
ht.put("-16158","leng");
ht.put("-16155","li");
ht.put("-15959","lia");
ht.put("-15958","lian");
ht.put("-15944","liang");
ht.put("-15933","liao");
ht.put("-15920","lie");
ht.put("-15915","lin");
ht.put("-15903","ling");
ht.put("-15889","liu");
ht.put("-15878","long");
ht.put("-15707","lou");
ht.put("-15701","lu");
ht.put("-15681","lv");
ht.put("-15667","luan");
ht.put("-15661","lue");
ht.put("-15659","lun");
ht.put("-15652","luo");
ht.put("-15640","ma");
ht.put("-15631","mai");
ht.put("-15625","man");
ht.put("-15454","mang");
ht.put("-15448","mao");
ht.put("-15436","me");
ht.put("-15435","mei");
ht.put("-15419","men");
ht.put("-15416","meng");
ht.put("-15408","mi");
ht.put("-15394","mian");
ht.put("-15385","miao");
ht.put("-15377","mie");
ht.put("-15375","min");
ht.put("-15369","ming");
ht.put("-15363","miu");
ht.put("-15362","mo");
ht.put("-15183","mou");
ht.put("-15180","mu");
ht.put("-15165","na");
ht.put("-15158","nai
补充:Web开发 , Jsp ,