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

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -