3

I have a list of String representations of unicode hex values such as "0x20000" () and "0x00F8" (ø) that I need to get the int code point of so that I can use functions such as: char[] chars = Character.toChars(0x20000);

This should cover the BMP as well as supplementary characters. I cannot find any way to do it so would be glad of some help.

syzygy
  • 33
  • 1
  • 3

1 Answers1

2

You can create your own NumberFormat implementation, but easier than that you can do something like this:

String hexString = "0x20000";
int hexInt = Integer.parseInt(hexString.substring(2), 16);
String stringRepresentation = new String(Character.toChars(hexInt));
System.out.println(stringRepresentation);   //prints ""
Mark Peters
  • 80,126
  • 17
  • 159
  • 190
  • Thanks. I tried that but got 131072 so thought it was not correct but got the right answer with Character.toChars(131072); – syzygy Jul 07 '11 at 21:55