RosettaCodeData/Task/Tokenize-a-string/Lua/tokenize-a-string-3.lua
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

11 lines
276 B
Lua

str = "Hello|How|Are|You||Today"
tokens = {}
for w in string.gmatch( str, "([^|]*)|?" ) do
tokens[#tokens+1] = w
end
table.remove(tokens)--pops off the last empty value, because without doing |? we lose the last element.
for i = 1, #tokens do
print( tokens[i] )
end