table.concat

From ComputerCraft
Jump to: navigation, search

table.concat
Function
Syntax
table.concat()
Returns string
API table
Source Lua (source)

Turn table into a string, provided that all of its elements can be coerced into a string. If a separator is specified, then it is inserted between each element. Additionally, concatenation starts at the ith element and ends at the jth.

ExampleExampleConcat an array of numbers
Since numbers are coercible to strings, an array of numbers can be concatenated.
Code
print(table.concat({ 1, 2, 3 }, ', '))
Output
1, 2, 3
ExampleExampleConcat a slice of an array
Concatenates an array of both strings and numbers, starting from the 3rd element up to the 5th.
Code
print(table.concat({ 1, 2, 3, "a", "b", 4, 5 }, ' ', 3, 5))
Output
3 a b