Posted By

chrisaiv on 04/27/09


utf8 ByteArray as3

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


AS3: How many bytes are in a UTF8 String

 / Published in: ActionScript 3


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.

  1. 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.";
  2. function getNumBytesUTF8 (s:String):Number {
  3. var byteArray:ByteArray = new ByteArray();
  4. byteArray.writeUTFBytes(s);
  5. return byteArray.length;
  6. }
  7. // Usage:
  8. trace(getNumBytesUTF8( string )); // 255

Report this snippet  

You need to login to post a comment.