Reputation: 221
I am completely new to lua and I would like some help. I have a Table of numbers in string format. How can I change them to integers? Is there a function that can do this. Or what is the best way.
input = {"1", "2", "3"}
output = {1, 2, 3}
For now I found only function tonumber
which changes a string to number. So I could solve this with a loop.
Upvotes: 1
Views: 378
Reputation: 28950
local input = {"1", "2", "3"}
local output = {}
for i = 1, #input do
output[i] = tonumber(input[i])
end
or
for i,v in ipairs(input) do
output[i] = tonumber(v)
end
Upvotes: 3