Posted 12 October 2012 - 06:21 PM
Here is what I'm trying to do:
Basically, I want to retreive all numbers from string. What I do is search for space, retreive number and then trim string.
It works great for the first number, but then string.find would start returning wierd values like string was never trimmed.
Any idea what am I doing wrong?
inputString = "1 20 3 45 5"
while inputString ~= nil do
local spaceLocation = string.find(inputString, " ")
if spaceLocation ~= nil then
number = tonumber(string.sub(inputString,1, spaceLocation))
inputString = string.sub(inputString, spaceLocation + 1)
else
number = tonumber(inputString)
inputString = nil
end
print(number)
end
Basically, I want to retreive all numbers from string. What I do is search for space, retreive number and then trim string.
It works great for the first number, but then string.find would start returning wierd values like string was never trimmed.
Any idea what am I doing wrong?