开发者

Unicode Supplementary Multilingual Plane in Java

开发者 https://www.devze.com 2022-12-17 04:15 出处:网络
I want to work with SMP(Supplementary Multilingual Plane) in Java. Actually, I want开发者_如何学运维 to print a character whose codepoint is more than 0xFFFF. I used this line of code:

I want to work with SMP(Supplementary Multilingual Plane) in Java. Actually, I want开发者_如何学运维 to print a character whose codepoint is more than 0xFFFF. I used this line of code:

int hexCodePoint = Character.toCodePoint('\uD801', '\uDC02' );

to have the codepoint of a special character. But how can I print this unicode character to the console?

Thank you in advance for your help.


String s = new StringBuilder().append("Here is a codepoint: ").appendCodePoint(hexCodePoint).toString();
System.out.println(s);

Note that in Windows it wouldn't produce the expected output due to the limited Unicode capabilities of the console

EDIT: Or Character.toChars(hexCodePoint) to produce char[]


System.out.println("\uD801\uDC02");

Now, whether U+10402 (𐐂) actually turns up on the console depends on:

  1. whether the encoding System.out converts to will transform the data to a lossy encoding (like a Windows "ANSI" codepage or MacRoman); see defaultCharset()
  2. whether the console supports the encoding System.out transforms the data to (sometimes, this is not the default on Windows consoles which use old OEM mappings)
  3. whether the console has font support for the character

Solutions to these problems will be platform-specific.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号