Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

what does the function table.concat do?

The wiki doesn't explain it too well, but what does it do?

1 answer

✓ Accepted answer

The concat function in the table library takes a table of strings and concatenates or puts them together:

local strings = {"foo" , "goo" , "bye world"}
local combinedStrings = table.concat(strings)
print(combinedStrings) --> foogoobye world

As you noticed above, the words do not have any spaces between them. The concat function has another optional argument which is a string to insert between each value:

local combinedStrings = table.concat(strings , " ")
print(combinedStrings) --> foo goo bye world

Finally, the concat function has two other optional arguments that tells a range in the table to concatenate rather then the whole thing:

local lotsOfStrings = {"S1" , "S2" , "S3" , "S4" , "S5" , "S6" , "S7" , "S8"}
local combinedStrings = table.concat(lotsOfStrings , " string " , 3 , 6)
print(combinedStrings) --> S3 string S4 string S5 string S6 string

This discussion is preserved as it was. New answers, comments, and votes are closed.