Code: Select all
function word(str,a,b) --assume str is 'Hello World'
for i,j in str:gmatch("%w+") do
a,b = i,j --catches I twice the second time its nil
end
return a,b
end
Code: Select all
function word(str) --assume str is 'Hello World'
for i,j in str:gmatch("%w+") do
return i,j --only catches I and quits
end
end
Code: Select all
function word(str) --assume str is 'Hello World'
for i,j in str:gmatch("%w+") do
print(i,j) --catches both I and j and prints
end
end
SOLVED:
I found a solution.
Code: Select all
function split(s, delimiter)
result = {}
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end
so the above code splits a string based on the delimiter for example " " (space) and stores that in a table result and returns that table.
Code: Select all
local splice = split(text," ")
input1,input2 = splice[1],splice[2]