utf8.charpos | Multi Theft Auto: Wiki Skip to content

utf8.charpos

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


Converts the UTF-8 codepoint position to byte-string position.

Note

Code point characters beyond the byte value range (0-127) require at least 2 bytes to represent the character

Syntax

int,​ int utf8.charpos utf8.charpos ( string input, [ [, int charpos = 0 ], int offset = 1 ] )
Required Arguments
  • input: A string character sequence
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • int charpos (default: 0 ]): MISSING_PARAM_DESC
  • offset (default: 1): An integer representing the offset to charpos.

Returns

  • int: value1
  • int utf8.charpos: value2

Returns the integer position as in a byte string and the integer codepoint at this position, nil otherwise.

Code Examples

shared

This example takes the second codepoint character and shows the byte-string position and the codepoint character code.

local position, codepoint = utf8.charpos( "Привет", 2 )
print( position, codepoint ) -- 3, 1088

See Also