lua - Get numerical values txt file using delimiters -
i have txt
file following text:
5;2;8;3;
i need numeric values, using ;
delimiter, , put them array. how achieved?
the easiest way use string.gmatch
match numbers:
local example = "5;2;8;3;" in string.gmatch(example, "%d+") print(i) end
output:
5 2 8 3
a "harder" way specific split
function:
function split(str, delimiter) local result = {} local regex = string.format("([^%s]+)%s", delimiter, delimiter) entry in str:gmatch(regex) table.insert(result, entry) end return result end local split_ex = split(example, ";") print(unpack(split_ex))
output:
5 2 8 3
have @ sample program here.
Comments
Post a Comment