You could try to use the split join method that was already written by our good friends at LUA
/>
This method splits a string by a certain pattern into a table and then returns said table:
-- Compatibility: Lua-5.1
function split(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
I DID NOT WRITE THIS!
^^ Code taken directly from
http://lua-users.org/wiki/SplitJoin
How you would apply this for splitting a word is calling the split method with a pattern of space:
local sSentence = "This is a cool string!"
local tWords = {}
tWords = split( sSentence, " " ) -- Split the string by spaces.
-- Print out the table.
for index,value in ipairs( tWords ) do
print( tWords[i] )
end
-- OUTPUT --
This
is
a
cool
string!
----------------
Hope I helped!
/>