Skip to content
Advertisement

How do I convert unicode codepoints to their character representation?

How do I convert strings representing code points to the appropriate character?

For example, I want to have a function which gets U+00E4 and returns รค.

I know that in the character class I have a function toChars(int codePoint) which takes an integer but there is no function which takes a string of this type.

Is there a built in function or do I have to do some transformation on the string to get the integer which I can send to the function?

Advertisement

Answer

Code points are written as hexadecimal numbers prefixed by U+

So,you can do this

int codepoint=Integer.parseInt(yourString.substring(2),16);
char[] ch=Character.toChars(codepoint);
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement