Revision: 13968
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at May 14, 2009 10:07 by sidneydekoning
Initial Code
// Handy ActionScript function that reports the number of bytes in a UTF-8 encoded string (the default encoding for ActionScript )
public function getNumBytesUTF8 (s:String):Number {
var byteArray:ByteArray = new ByteArray();
byteArray.writeUTFBytes(s);
return byteArray.length;
}
// Usage:
trace(getNumBytesUTF8("automobile")); // 10
trace(getNumBytesUTF8("車")); // 3
// Note: "number of bytes" is not the same thing as "number of characters". For "number of characters," use the String class's length variable:
trace("車".length); // 1
Initial URL
Initial Description
Initial Title
Read UTF8 Bytes
Initial Tags
Initial Language
ActionScript 3