Java获取字符串Unicode编码
程序员文章站
2022-07-14 19:40:57
...
public static String getUnicode(String str) {
char[] cs = str.toCharArray();
String result = "";
for (char c : cs) {
String s = Integer.toHexString(c);
if (s.length() == 2) {
s = "\\u00" + s;
} else {
s = "\\u" + s;
}
result += s;
}
return result;
}
下一篇: Java进阶(三十) 判断字符串编码类型