Showing A Utf16-le Encoded String In Textview For Android
I have a UTF-16LE encoded string that comes from a server. I would like to print that string in Textview of my activity. However, the string prints with spaces in between them. So,
Solution 1:
Assuming you have a stream (or array of byte
s) containing a UTF-16LE encoded string.
Stringstr0="Hello, I am a UTF-16LE encoded String";
byte[] utf16le = str.getBytes("UTF-16LE");
If you do not convert these back & stating the character set used you will be producing a string containing a lot of 0-bytes (UTF-16LE is, obviously, 16-bit) in your resulting String.
String wrong = newString(utf16le); // This will produce crap with \0:s in it.String correct = newString(utf16le, "UTF-16LE"); // This will be the actual string.
Note: If you dump crap String:s like these into a TextView in ICS it will remove the garbage for you and not print "H e l l o".
Post a Comment for "Showing A Utf16-le Encoded String In Textview For Android"