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

[lua] question on tables

Started by tom2018, 23 March 2013 - 11:15 AM
tom2018 #1
Posted 23 March 2013 - 12:15 PM
if i have a table like this
t = {"h","i"}
how do i turn that into
"hi"
?
Kingdaro #2
Posted 23 March 2013 - 12:19 PM
Two methods.

Harder way, but with more flexibility:

local str = ''
for i=1, #t do
  str = str .. t[i]
end
print(str) --> hi

Easier way, less flexibility, but perfect for your purposes.

local str = table.concat(t)
print(str) --> hi

In the future, you can also use an optional separator with table.concat if you want.

local str = table.concat(t, ',')
print(str) --> h,i