码迷,mamicode.com
首页 > 其他好文 > 详细

unicode 中文转换

时间:2016-01-13 11:04:01      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:unicode

public static String getStrUnicode(String inStr) {

StringBuffer unicode = new StringBuffer();

char c;

int bit;

String tmp = null;

for (int i = 0; i < inStr.length(); i++) {

c = inStr.charAt(i);

if (c > 255) {

unicode.append("\\u");

bit = (c >>> 8);

tmp = Integer.toHexString(bit);

if (tmp.length() == 1)

unicode.append("0");

unicode.append(tmp);

bit = (c & 0xFF);

tmp = Integer.toHexString(bit);

if (tmp.length() == 1)

unicode.append("0");

unicode.append(tmp);

} else {

unicode.append(c);

}

}

return (new String(unicode));

}


unicode 中文转换

标签:unicode

原文地址:http://session.blog.51cto.com/8308112/1734437

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!