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

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -