Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put a supplementary Unicode character in a string literal?

Tags:

People also ask

How do you add a Unicode to a string?

To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X. For more Unicode character codes, see Unicode character code charts by script.

What is Unicode string literal?

If the character string literal has a prefix of N, the literal is treated as a Unicode string. When the N prefix is used, the characters in the literal are read as WCHAR characters. Any string literal with non-ASCII characters is treated as a Unicode literal by default.

What is character u '\ xe9?

u'\xe9' is a Unicode string that contains the unicode character U+00E9 (LATIN SMALL LETTER E WITH ACUTE).

How do you add a character to a string?

Insert a character at the beginning of the String using the + operator. Insert a character at the end of the String using the + operator.


How to put a supplementary Unicode character (say, codepoint 10400) in a string literal? I have tried putting a surrogate pair like this:

String text = "TEST \uD801\uDC00"; System.out.println(text); 

but it doesn't seem to work.

UPDATE:

The good news is, the string is constructed properly.
Byte array in UTF-8: 54 45 53 54 20 f0 90 90 80
Byte array in UTF-16: fe ff 0 54 0 45 0 53 0 54 0 20 d8 1 dc 0

But the bad news is, it is not printed properly (in my Fedora box) and I can see a square instead of the expected symbol (my console didn't support unicode properly).