RawData.setUtf8

From MiniScript Wiki
Revision as of 23:25, 29 January 2025 by FR-b0n5a1 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

RawData.setUtf8 writes 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 number 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.