Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

what does the function table.concat do?

Asked by 6 years ago

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

1 answer

Log in to vote
6
Answered by
RayCurse 1518 Moderation Voter
6 years ago
Edited 6 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
Ad

Answer this question