/**
* 将Native编码的字符串转化为Unicode编码的字符
*
* @param str
* @return String
*/
public static String ascii2Native(String str) {
try {
byte[] buffer = new byte[str.length() * 2];
int j = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) >= 0x100) { //256
char c = str.charAt(i);
byte[] buf = ("" + c).getBytes();
buffer[j++] = (byte) buf[0];
buffer[j++] = (byte) buf[1];
} else {
buffer[j++] = (byte) str.charAt(i);
}
}
return new String(buffer, 0, j);
} catch (Exception e) {
byte[] b = str.getBytes();
try {
return new String(b, "gb2312");
} catch (Exception e1) {
return "";
}
}
}
将Native编码的字符串转化为Unicode编码的字符
最新推荐文章于 2024-04-07 15:39:03 发布