//24503jiulylguo38451jiulylguo24066jiulylguo53jiulylguo53jiulylguo98jiulylguo98jiulylguo
String recognition="德阳市55bb";
String name="";
//把汉字转化成字符
char[] chars=recognition.trim().toCharArray(); //把字符中转换为字符数组
for(int j=0;j<chars.length;j++){//输出结果
name=name+(int)chars[j]+"jiulylguo";
}
//把字符转化成汉字
Pattern p = Pattern.compile("^[\\djiulylguo]+$");
Matcher matcher = p.matcher(name);
boolean b = matcher.matches();
String dencoder = "";
if (b) {
String[] cs = name.split("jiulylguo");
// System.out.println("ASCII 汉字 \n----------------------");
for (int j = 0; j < cs.length; j++) {
dencoder = dencoder + (char) Integer.parseInt(cs[j]);
}
}
Java转换html转义字符
String str1 = "特别";
String[] str= str1.split(";");
String sResult = "";
for (int i = 0; i < str.length; i++) {
int str2 = Integer.parseInt(str[i].replace("&#", ""));
sResult += ""+(char)str2;
}
System.out.println(sResult);
------------------------------------------------------
String src = "测试";
String htmlStr = "";
String cnStr = "";
for(int i=0; i!=src.length(); i++){
int str = src.codePointAt(i);
htmlStr = htmlStr+"&#"+str+";";
cnStr = cnStr+""+(char)str;
}
System.out.println("汉字到html转义符 ==> " + htmlStr);
System.out.println("html转义符到汉字 ==> " + cnStr);