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,中文转换)