RawData.setUtf8

From MiniScript Wiki
Revision as of 17:16, 12 March 2022 by JoeStrout (talk | contribs) (Created page with "<c>RawData.setUtf8</c> wr.srites a string into a RawData buffer in UTF-8 format, and returns the number of bytes written. === Arguments === {| class="wikitable" |- ! Par...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.

Arguments

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

Returns

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.

Example

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.