Issue
In java,
Unicode characters can be represented using unicode escape sequence for UTF-16
encoding. Below is an example that represents BMP plane character
char ch = '\u00A5'; // '¥'
Can surrogate pairs be used for non-BMP plane characters?
char ch4 = '\uD800\uDC00'; //Invalid character constant
How do I represent non-BMP plane character using java syntax?
Solution
You cannot do that with a single char constant, since a char is a UTF-16 code unit. You have to use a String constant, such as:
final String s = "\uXXXX\uYYYY";
where XXXX
is the high surrogate and YYYY
is the low surrogate.
Another solution is to use an int
to store the code point; you can then use Character.toChars()
to obtain a char[]
out of it:
final int codePoint = 0x1f4ae; // for instance
final char[] toChars = Charater.toChars(codePoint);
Depending on what you use, you may also append code points directly (a StringBuilder
has a method for that, for instance).
Answered By - fge
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.