i need to split each row of a input file using the specific pattern " - ". I'm not so far from solution but my code actually splits also single spaces. Each row of the file is formatted as follow:
NAME - ID - USERNAME - GROUP NAME - GROUP ID - TIMESTAMP
name field may have spaces, same as group name and timestamp, for example a row like that
LUCKY STRIKE - 11223344 - @lucky - CIGARETTES SMOKERS - 44332211 - 11:42 may/5th
is valid. So these tokenized values should be stored inside a table. Here is my code:
local function splitstring(inputstr)
sep = "(%s-%s)"
local t={} ; i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
print("=========="..t[1].."===========")
print("=========="..t[2].."===========")
print("=========="..t[3].."===========")
return t
end
when i run it, puts "lucky" in first field, strike in second field, the id inside third field. Is there a way to store "lucky strike" inside first field, parsing ONLY by pattern specified? Hope you guys could help me.
p.s. I already see the lua manual but didn't help me so much...
t = {inputstr:gsub('%s+%-%s+','\0'):match(('.-(%Z+)'):rep(6))}- Egor Skriptunoff