New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
1

# what does the function table.concat do?

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

6
RayCurse 1498
2 years ago
Edited 2 years ago

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