139 posts
Posted 27 October 2012 - 05:03 PM
Ok i would like to know how i would take
x = "hello"
and turn it into
x = {"h","e","l","l","o"}
thanks
137 posts
Location
the Netherlands
Posted 27 October 2012 - 05:26 PM
x = "hello"
y= {}
for a=1,#x do
y[a]=x:sub(a,a)
end
using #sometext you can get the length of a string
using "derp":sub(a,b ) you can get the string between position a and b
2005 posts
Posted 27 October 2012 - 06:36 PM
string.gmatch is a good way to turn strings into table elements, because it's iterative so it works well with a for v in type loop. But you can do the same with an iterative loop that uses string.sub and the #x.
Of course, since you can already access any individual character in a string using string.sub, you can probably just use the string as it is for most things.
139 posts
Posted 27 October 2012 - 06:46 PM
thanks
8543 posts
Posted 27 October 2012 - 08:30 PM
Yeah, string.gmatch is useful:
str = "hello"
strTable = {}
for char in string.gmatch(str, ".") do
table.insert(strTable, char)
end