实现和 jdk\bin\native2ascii.exe 同样的功能
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));
}
|----------------------------------------------------------------------------------------|
版权声明 版权所有 @zhyiwww
引用请注明来源 http://www.blogjava.net/zhyiwww
|----------------------------------------------------------------------------------------|
posted on 2006-07-12 12:40
zhyiwww 阅读(948)
评论(1) 编辑 收藏 所属分类:
code demo -java