Type Function Library utf8.* Return value Numbers or iterator Revision 2017.3060 Keywords utf8, UTF-8, Unicode, string, next
Examines or iterates through a
If only charpos
is specified, returns the next byte offset in the string.
If charpos
and offset
are specified, a new charpos
will be calculated by adding or subtracting the charpos
.
If the parentheses are omitted, it can used directly as an iterator:
for charpos, codepoint in utf8.next, "UTF8-string" do print( charpos, codepoint ) end
In all cases, this function returns a new character position (in bytes) and code point (number) at this position.
utf8.next( s [, charpos [, offset]] )
String. The string.
Number. The character position to start at.
Number. The character offset.
local utf8 = require( "plugin.utf8" ) local testStr = "♡ 你好,世界 ♡" print( utf8.next( testStr, 2 ) ) --> 3 161
local utf8 = require( "plugin.utf8" ) local testStr = "♡ 你好,世界 ♡" for charpos, codepoint in utf8.next, testStr do print( charpos, codepoint ) end --> 1 9825 --> 4 32 --> 5 20320 --> 8 22909 --> 11 65292 --> 14 19990 --> 17 30028 --> 20 32 --> 21 9825