local items = {}
local t = "7 2182, 4 2554, 5 9908"
I wanted to convert using this string and let the table go like this:
local items = {{7,2182},{4,2554},{5,9908}}
Is there a way? using gsub maybe?
local items = {}
local t = "7 2182, 4 2554, 5 9908"
I wanted to convert using this string and let the table go like this:
local items = {{7,2182},{4,2554},{5,9908}}
Is there a way? using gsub maybe?
Try the code below:
local items = {}
local t = "7 2182, 4 2554, 5 9908"
local n = 0
for a,b in t:gmatch("(%d+)%s+(%d+)") do
n = n + 1
items[n] = {a,b}
end
for k,v in ipairs(items) do print(k,v[1],v[2]) end
The pattern in t:gmatch
captures two digit sequences separated by spaces.