经典java转码程序,有备无患!实现和 jdkin ative2ascii.exe 同样的功能

类别:编程语言 点击:0 评论:0 推荐:
private String convert(String str)
{
String tmp;
StringBuffer sb = new StringBuffer(1000);
char c;
int i, j;
sb.setLength(0);
for(i = 0;i<str.length();i++){
c = str.charAt(i);
if (c > 255) {
sb.append("\\u");
j = (c >>> 8);
tmp = Integer.toHexString(j);
if (tmp.length() == 1) sb.append("0");
sb.append(tmp);
j = (c & 0xFF);
tmp = Integer.toHexString(j);
if (tmp.length() == 1) sb.append("0");
sb.append(tmp);
}
else {
sb.append(c);
}

}return(new String(sb));
}

本文地址:http://com.8s8s.com/it/it25217.htm