AS3: How many bytes are in a UTF8 String


/ Published in: ActionScript 3
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.