我需要将 unicode 文字字符串打印为等效的 unicode 字符。
System.out.println("\u00A5"); // prints ¥
System.out.println("\\u"+"00A5"); //prints \u0045 I need to print it as ¥
如何将此字符串评估为 unicode 字符?
我需要将 unicode 文字字符串打印为等效的 unicode 字符。
System.out.println("\u00A5"); // prints ¥
System.out.println("\\u"+"00A5"); //prints \u0045 I need to print it as ¥
如何将此字符串评估为 unicode 字符?
作为此处其他选项的替代方案,您可以使用:
int codepoint = 0x00A5; // Generate this however you want, maybe with Integer.parseInt
String s = String.valueOf(Character.toChars(codepoint));
与其他提议的技术相比,这将具有优势,因为它也可以与基本多语言平面之外的 Unicode 代码点一起使用。
将其转换为字符。
System.out.println((char) 0x00A5);
这当然不适用于非常高的代码点,可能需要 2 个“字符”。
如果你有一个字符串:
System.out.println((char)(Integer.parseInt("00A5",16)));
可能有效(尚未测试)