输入汉字自动转为拼音(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");
相关新闻>>
- 发表评论
-
- 最新评论 更多>>