376 posts
Location
[string "FindMe"]:23143: bad argument #1 to 'returnPos' (vector expected, got nil)
Posted 30 May 2014 - 01:29 AM
Imagine I wanted to split lets say "Hello World!" into a table and the table show up as :
example = {"H","e","l","l","o"," ","W","o","r","l","d","!"}
Does anybody know how to do this? All help is appreciated
7083 posts
Location
Tasmania (AU)
Posted 30 May 2014 - 01:38 AM
Well, you could put all the characters into a table by iterating through the string with string.sub, I suppose, but I suspect you'd be better off leaving them where they are and string.sub'ing them out when you actually
need them.
In any case, assuming you're already familiar with tables and loops and such, have a read through
the string-related functions here.
1610 posts
Posted 30 May 2014 - 05:23 AM
Well, normally I wouldn't write code for AAP, but it's pretty simple, so meh:
function toTable(str)
local tbl = {}
for i = 1, #str do
table.insert(tbl,string.sub(str,i,i))
end
return tbl
end
Edited on 30 May 2014 - 03:24 AM