Difference between revisions of "RawData.setUtf8"
Jump to navigation
Jump to search
(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...") |
m |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
− | <c>RawData.setUtf8</c> | + | <c>[[RawData]].setUtf8</c> writes a string into a [[RawData]] buffer in UTF-8 format, and returns the number of bytes written. |
=== Arguments === | === Arguments === | ||
Line 7: | Line 7: | ||
! Parameter Name !! Type !! Default Value !! Meaning | ! Parameter Name !! Type !! Default Value !! Meaning | ||
|- | |- | ||
− | | ''offset'' || | + | | ''offset'' || number || 0 || position in buffer at which to start writing |
|- | |- | ||
| ''s'' || string || "" || string to write | | ''s'' || string || "" || string to write |
Latest revision as of 23:25, 29 January 2025
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.