CreateByteArrayFromString

From Spheriki

Jump to: navigation, search

Creates a Sphere ByteArray object, containing the contents of the supplied string.


Contents

Usage

ByteArray CreateByteArrayFromString(string);
  • string String. Whatever text that needs to be turned into a ByteArray.


Examples

var rf = OpenRawFile("blah.dat", true);
rf.write(CreateByteArrayFromString("Waffles are like pancakes with syrup traps!"));
rf.close();

This small snippet of code creates or overwrites the file other/blah.dat with the given string "Waffles are like pancakes with syrup traps!" Observing the file will prove this fact.


const MSG = "ABC abc";

var ba = CreateByteArrayFromString(MSG);
var char_vals = ba[0];

for (var i = 1; i < ba.length; ++i)
  char_vals += ", " + ba[i];

Abort(MSG + " = " + char_vals + "\n");

The above will output the values of each element of the generated ByteArray.

ABC abc = 65, 66, 67, 32, 97, 98, 99


Notes

  • Internally, each character of the string is turned into a single byte of the ByteArray. The length of the returned ByteArray is therefore the length of the string itself, when initially created.


See also

Personal tools