假设我有一个字符串 foo = "This is an apple"
等效的 Unicode 代码点将是
"\\x74\\x68\\x69\\x73.........\\x61\\x70\\x70\\x6c\\x65
"
T h i s ............. a p p l e
如何从字符串 foo 转换
到
字符串“\\x74\\x68\\x69\\x73.........\\x61\\x70\\x70\\x6c\\x65
”
最佳答案
试试这个..
public static String generateUnicode(String input) {
StringBuilder b = new StringBuilder(input.length());
for (char c : input.toCharArray()) {
b.append(String.format("\\u%04x", (int) c));
}
return b.toString();
}
关于java - 将字符串转换为其 Unicode 代码点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30940095/