Return to Snippet

Revision: 13540
at April 27, 2009 12:04 by chrisaiv


Initial Code
var string:String = "i am testing how many bytes ther are in this particular tweet.  I'm hoping it's roughly 255 because I will have answered the secret to life.";
 function getNumBytesUTF8 (s:String):Number {
  var byteArray:ByteArray = new ByteArray();
  byteArray.writeUTFBytes(s);
  return byteArray.length;
}
// Usage:
trace(getNumBytesUTF8( string ));  // 255

Initial URL
http://www.moock.org/blog/archives/000288.html

Initial Description
This example explains why Twitter has a 140 character limit.  It shows that the DataType they are using to write to their database is a tinyblob or tinytext.

Initial Title
AS3: How many bytes are in a UTF8 String

Initial Tags


Initial Language
ActionScript 3