Jeff said:
Hi,
How can I convert a String containing a
Java Unicode escape sequence to a String
containing the equivalent UTF8 representation?
For instance "\u4f55" -> "e4bd95"
Thanks,
Jeff Higgins
Ok,
Thanks everyone for the generous responses.
SadRed for the pointer to the UTF8 definition.
I found it kind of hard to follow at first, but
now that I've found some code to follow along
with, it's making more sense. Bugbear for the
NIO example, as you can see I struggle with basic
IO now I need to understand wrapping and flipping.
And Roedy whose excellent mindprod site has been
a continuing source of enlightenment, Thanks.
Anyway,
for anyone else who read my OP and was
only able to shake their head in amazement at
it's utter incomprehensibility, here is what I
had \really\ hoped to accomplish.
How to encode a Unicode scalar value in UTF8?
public class Encode
{
public static void main(String[] args)
{
int[] intArray = {0x4f55};
byte[] byteArray = encode(intArray);
for(byte b : byteArray)
{
System.out.print(Integer.toString((b & 0xff) + 0x100,
16).substring(1));
}
}
}
prints e4bd95
where encode(int[]) is a method described at:
<
http://developers.sun.com/dev/gadc/technicalpublications/articles/utf8.html>