Lua - extract a string using patterns -


i'm starting on lua patterns.

i have string |2|34|56|1

how extract numbers string?

i can parse string manually , exclude '|' characters. i'm sure using lua patterns simpler.

how patterns in case?

if want print numbers, best method is:

str = "|2|34|56|1" str:gsub("%d+", print) 

else, if want numbers stored in table, longer approach required:

str = "|2|34|56|1" local tfinal = {} str:gsub( "%d+", function(i) table.insert(tfinal, i) end) table.foreach(tfinal, print) -- verify numbers have been stored table. 

Comments

Popular posts from this blog

JQuery Autocomplete without using label, value, id -

c++ - Accessing inactive union member and undefined behavior? -

JAVA - what is the difference between void and boolean methods? -