lua - Get the first value from an iterator -
i split string separator , last part. don't care rest. know can do:
local last p in string.gmatch('file_name_test', '_%w+$') last = p end which works, is, imho, ugly.
is there more elegant way say:
local last = string.gmatch('file_name_test', '_%w+$')[1] which doesn't work because gmatch returns iterator (and not table).
although other answers give correct answer situation, going propose answer question. first item iterator.
and answer quite simple. since iterator continues return until returns nil, have call it!
local first = string.gmatch('file_name_test', '_%w+$')() i quite confused however, because in question ask last thing return. i'm sad cannot without iterating on them all, because iterator cannot "jump ahead".
Comments
Post a Comment