Type Function Library utf8.* Return value Numbers Revision 2017.3060 Keywords utf8, UTF-8, Unicode, string, charpos See also utf8.codepoint()
Converts UTF-8 position to byte offset depending on usage:
If only offset
is specified, returns the byte offset of this
If charpos
and offset
are specified, a new charpos
will be calculated by adding or subtracting the charpos
.
In both cases, this function returns a new character position and code point (number) at this position.
utf8.charpos( s, [charpos,] offset )
String. Any string.
Number. The character position in the
Number. The character offset.
local utf8 = require( "plugin.utf8" ) local testStr = "♡ 你好,世界 ♡" print( utf8.sub( testStr, 3, 3 ) ) --> 你 print( utf8.charpos( testStr, 3 ) ) --> 5 20320