CreateByteArrayFromString
From Spheriki
Creates a Sphere ByteArray object, containing the contents of the supplied string.
Contents |
[edit]
Usage
ByteArray CreateByteArrayFromString(string);
- string String. Whatever text that needs to be turned into a ByteArray.
[edit]
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
[edit]
Notes
- To create a blank ByteArray, use the CreateByteArray() function.
- To revert a string that is in ByteArray form, use the CreateStringFromByteArray() function.
- 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.
[edit]
See also
- Sphere ByteArray object
- CreateByteArray()
- CreateStringFromByteArray()
- Sphere RawFile object

