table.concat()

Type Function
Library table.*
Return value String
Revision Current Public Release (2017.3068)
Keywords table, array
See also table.insert()

Overview

Concatenate the elements of a table together to form a string. Each element must be able to be coerced into a string. A separator can be specified which is placed between concatenated elements.

Syntax

table.concat( t )

table.concat( t, sep )

table.concat( t, sep, i )

table.concat( t, sep, i, j )
t (required)

Array. An array where all elements are strings or numbers.

sep (optional)

String. The string to insert between concatenated table values. The default value is the empty string.

i (optional)

Number. . The beginning table index to be concatenated. The default value is 1.

j (optional)

Number. . The ending table index to be concatenated. The default value is the length of the array t. If i is greater than j, returns the empty string.

Example

local t = { 1, 2, "three", 4, "five" }
print( table.concat(t) )              --> 12three4five
print( table.concat(t, ", ") )        --> 1, 2, three, 4, five
print( table.concat(t, ", ", 2, 4) )  --> 2, three, 4