开发者

Get the byte length of a string

开发者 https://www.devze.com 2023-01-14 16:46 出处:网络
Is there an easy way to get the byte length of a string in AS3? String.le开发者_StackOverflow社区ngth works in many cases, but breaks if it encounters mulibyte unicode characters.

Is there an easy way to get the byte length of a string in AS3? String.le开发者_StackOverflow社区ngth 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,").


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号