Skip to main content
Inspiring
March 11, 2010
Question

utf-16 problems when using writeUTFBytes and readUTFBytes

  • March 11, 2010
  • 1 reply
  • 358 views

I'm really confused about the 'unicode' chatset as it does not seem to do what I would think it would do.

Every utf16 character is represented by 2 bytes. So a "C" would have 2 bytes [67,0], a chinese character would have 2 bytes also.

var testStr:String = '漢語';
var testBA:ByteArray = new ByteArray();
testBA.writeMultiByte(testStr,'unicode');
testBA.position = 0;
for(var a=0;a<testBA.length;a++)
{
    trace(testBA);
}
var str:String = testBA.readMultiByte(testBA.length,'unicode');
trace(str);

OUTPUT:
63
63
??

The testBA should have 4 bytes shouldnt it?
Can anyone show an example of how to convert my test String to and then back from UTF-16?

This topic has been closed for replies.

1 reply

Participant
March 15, 2010

Surely there is a simply answer to this? Why have the string conversions if they dont work?