Ok i would like to know how i would take
x = "hello"
and turn it into
x = {"h","e","l","l","o"}
thanks
help with tables/variables needed
Started by tom2018, Oct 27 2012 04:03 PM
4 replies to this topic
#1
Posted 27 October 2012 - 04:03 PM
#2
Posted 27 October 2012 - 04: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 stringusing "derp":sub(a,b ) you can get the string between position a and b
#3
Posted 27 October 2012 - 05: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.
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.
#4
Posted 27 October 2012 - 05:46 PM
thanks
#5
Posted 27 October 2012 - 07:30 PM
Yeah, string.gmatch is useful:
str = "hello"
strTable = {}
for char in string.gmatch(str, ".") do
table.insert(strTable, char)
end
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











