I have the following string:
example = "1,3,4-7,9,13-17"
With these values I want the next array: 1,3,4,5,6,7,9,13,14,15,16,17
With the script below I get the values between the commas, but how do I get the rest.
teststring = "1,3,4-7,9,13-17"
testtable=split(teststring, ",");
for i = 1,#testtable do
print(testtable[i])
end;
function split(pString, pPattern)
local Table = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pPattern
local last_end = 1
local s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
Output
1
3
4-7
9
13-17