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 mulibyte unicode characters.
(in this particular case, I need to know this so I can preface messages sent across a TCP socket with the message length. This is in standard netstring format e.g. "length:message,").
In Java, String. length() is to return the number of characters in the string, while String. getBytes(). length is to return the number of bytes to represent the string with the specified encoding.
If you want the size of the string in bytes, you can use the getsizeof() method from the sys module.
If the pixel dimensions are given, multiply them by each other and the bit depth to determine the number of bits in an image file. For instance, if a 24-bit image is captured with a digital camera with pixel dimensions of 2,048 x 3,072, then the file size equals (2048 x 3072 x 24)/8, or 18,874,368 bytes.
A 16 byte field can hold up to 16 ASCII characters, or perhaps 8 CJK glyphs that might encode a short kanji or hanzi password. "A 16 byte field can hold up to 16 ASCII characters, or perhaps 8 CJK glyphs that might encode a short kanji or hanzi password."
Use a ByteArray like so:
var b:ByteArray = new ByteArray();
b.writeUTFBytes("This is my test string");
trace("Byte length: " + b.length);
Info on ByteArray here: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/utils/ByteArray.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With