Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>is it possible to write past the null byte into the ByteArray()?</p> </blockquote> <p>Of course it is. <code>ByteArray</code> -- is a chunk of raw data. You can write whatever you like there, and you can read in whatever way you like (using zero bytes as delimiters or whatever else you may want to do).</p> <p>What you see when you send your bytes to standard output with <code>trace()</code>, depends solely on what you actually do with your data to convert it to a string. There are several ways of converting an array of bytes to string. So, your question is missing the explanation of what <code>Util.print()</code> method does.</p> <p>Here are several options for converting bytes to a string:</p> <ul> <li>Loop through bytes and output characters, encoding is up to you.</li> <li>Read a string with <a href="http://livedocs.adobe.com/livecycle/8.2/programLC/common/langref/flash/utils/ByteArray.html#readUTFBytes%28%29" rel="nofollow">ByteArray.readUTFBytes()</a>. This method reads utf-encoded symbols; it stops when zero character is encountered.</li> <li>Read a string with <a href="http://livedocs.adobe.com/livecycle/8.2/programLC/common/langref/flash/utils/ByteArray.html#readUTFBytes%28%29" rel="nofollow">ByteArray.readUTF()</a>. This method expects your string to be prefixed with unsigned short indicating its length. In other terms it is the same as <code>ByteArray.readUTFBytes()</code>.</li> <li>Use <a href="http://livedocs.adobe.com/livecycle/8.2/programLC/common/langref/flash/utils/ByteArray.html#toString%28%29" rel="nofollow">ByteArray.toString()</a>. This is what happens when you simply do <code>trace(byteArray);</code>. This method ignores zero bytes and outputs the rest. This method uses <code>System.useCodePage</code> setting to decide on the encoding, and can use UTF BOM if the data begins with it.</li> </ul> <p>Here are some tests that illustrate the above:</p> <pre><code>var test:ByteArray = new ByteArray(); // latin (1 byte per character) test.writeUTFBytes("ABC"); // zero byte test.writeByte(0); // cyrillic (2 bytes per character) test.writeUTFBytes("\u0410\u0411\u0412"); trace(test); // ABCАБВ trace(test.toString()); // ABCАБВ test.position = 0; trace(test.readUTFBytes(test.length)); // ABC // simple loop var output:String = ""; var byte:uint; for (var i:uint = 0; i&lt;test.length; i+=1) { byte = uint(test[i]); if (output.length &amp;&amp; i%4 == 0) { output += " "; } output += (byte &gt; 0xF ? "" : "0") + byte.toString(16); } trace(output); // 41424300 d090d091 d092 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload