From MiniScript Wiki
Jump to navigation Jump to search

RawData.setUtf8 wr.srites a string into a RawData buffer in UTF-8 format, and returns the number of bytes written.


Parameter Name Type Default Value Meaning
offset string 0 position in buffer at which to start writing
s string "" string to write


This function returns the number of bytes written. If the given string contains only ASCII characters, than this is equal to the len of the string. If it contains any non-ASCII characters, then it will be more than the length of the string, since non-ASCII characters require multiple bytes to represent in UTF-8.


r = new RawData
r.resize 32
print r.setUtf8(4, "Hello!")

This example creates a RawData buffer, sizes it to 32 bytes, and then writes the string "Hello!" starting at byte 4. It prints out 6, as that is the number of bytes in the string.