This content has been marked as final. Show 5 replies
My subject line might not be very clear so changing it here. I know that java String is already unicode.
Is there any equivalent method of Character.codePointAt() in java 1.4.2
Again I am trying to get unicode code point value from String (Unicode string).
Casting a char to an int is probably at the root of what you are asking.
And converting a single char whose hexadecimal value is abcd into the six-character string "\uabcd" is unlikely to be a useful thing to do.
I tried to do what that but I am not sure whether that is right or not.
String inputStr = "some non ascii string";
char charArray = inputStr.toCharArray();
StringBuffer sb = new StringBuffer();
for(int i = 0; i < charArray.length; i++)
code = (int) charArray;
String hexString = Integer.toHexString( code );
System.out.println("Code point is "+sb.toString());
My above code does not work as expected. Could you please tell me where i am goofing?
A Unicode escape has to contain four hex digits, but toHexString() only uses as many digits as it needs to. You could add leading zeroes, but if you're running JDK 1.5 or later, there's an easier way.
String uEscape = String.format("\\u%4s", code);