Does this work for you?
local function split( text )
local t = {}
for i = 1, #text do
table.insert( t, text:sub( i, i ) )
end
return t
end
--# Example usage, inconvenient way to write "Hello World!" :-P
for _, char in ipairs( split( "Hello World!" ) ) do
write( char )
end
I'll try to explain everything as best as I can, I think you know some of the basics atleast( for loops, functions, variable types )
So when we first loop through the text we start at 1, and continue until the end of the string,
#text gets the length of the string or table, it would essentially be the same as doing
string.len( text ), but it's simpler and therefore I'll go with it.
In the loop we use
table.insert to insert the character into the table we'll return from the function, we get each character by using
string.sub( startIndex, lastIndex ) Now we use the loop variable( "i" in this example ) and sub the string to that, we use the same variable on the
startIndex and the
lastIndex so we get the character there.
When we've finally looped through the string we simply return it.