This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ETHANATOR360's profile picture

turning table data into one string

Started by ETHANATOR360, 04 March 2013 - 10:32 AM
ETHANATOR360 #1
Posted 04 March 2013 - 11:32 AM
how do you get a table like:
letters = {"a", "b", "c"}
to
"abc"
LBPHacker #2
Posted 04 March 2013 - 11:35 AM

local output = ""
local mytable = {"a", "b", "c"}

for i = 1, #mytable do output = output .. mytable[i] end

print(output)

You want me to explain?
Kingdaro #3
Posted 04 March 2013 - 11:36 AM
Nicer way:


str = table.concat(letters)
print(str)

Only works with tables with numeric indices though.
LBPHacker #4
Posted 04 March 2013 - 11:37 AM
Now that's why YOU are the "Lua God" and I am the "Scripter" :D/>
PixelToast #5
Posted 04 March 2013 - 11:40 AM
usage is table.concat("string","spacer")
spacer can be anything separating the table elements (including nil or "")
LBPHacker #6
Posted 04 March 2013 - 11:44 AM
-snip-
I know what table.concat is, I just have no experience with it yet. That's why I haven't mentioned it…

(I know that that post was mainly an answer for ETHANATOR - or at least I hope so…)