Posted 14 February 2015 - 10:04 AM
How would I loop through all the chars in the string and put them inside a table?
local mystring = "hello"
local chars = { }
for i = 1, #mystring do
chars[i] = mystring:sub(1, 1)
end
Your code will not work.Haven't tested it, but something like this should do the job.local mystring = "hello" local chars = { } for i = 1, #mystring do chars[i] = mystring:sub(1, 1) end
local mystring = "hello"
local chars = { }
for i = 1, #mystring do
chars[#chars + 1] = mystring:sub(i, i) --#1's here should of been i.
end
Mind you, chars was perfectly fine. Certainly better than pulling the length and adding one over and over.
Double-mind you, you may as well just leave the characters in the string and sub 'em out as needed. Is there any particular need to mirror them into a table?