Converting String to unicode encoded string
Hi,
I would like to convert non-ascii characters in a String or the whole string to unicode encoded character.
For example:
If i have some japanese character, I would like it to be converted to /uxxxx
How can i do this? I don't want the exact character, as I am able to get that using getBytes("encoding format"). All i want is code point representation of the non ascii unicode characters.
Any help to do this will be appreciated.
Thanks in advance.
[495 byte] By [
DeepSofta] at [2007-11-26 22:59:10]

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();
int code;
StringBuffer sb = new StringBuffer();
for(int i = 0; i < charArray.length; i++)
{
code = (int) charArray;
String hexString = Integer.toHexString( code );
sb.append(hexString);
}
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?
Thanks!
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);