Get string byte length

Is there an easy way to get the byte length of a string in AS3? String.length works in many cases, but breaks if it encounters unicode mulibyte characters.

(in this particular case, I need to know this so that I can send messages sent over a TCP socket with a message length. This is in the standard netstring format, for example, "length: message",).

+4
source share
1 answer

Use ByteArray as follows:

 var b:ByteArray = new ByteArray(); b.writeUTFBytes("This is my test string"); trace("Byte length: " + b.length); 


Information about ByteArray here: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/ByteArray.html
+5
source

All Articles