Vital.sandbox
Table

table.concat

Shared

Concatenates table elements into a single string


Syntax

local result = table.concat(input, separator = "", start_at = 1, end_at = table.len(input))

Parameters

TypeNameDescription
tableinputTable to be concatenated
stringseparatorString to insert between concatenated elements
intstart_atPosition where concatenation starts
intend_atPosition where concatenation ends

Returns

TypeNameDescription
stringresultConcatenated string

Examples

--Concatenate all elements
local t = {"hello", "world", "lua"}
local result = table.concat(t)
engine.print(result) --helloworldlua
--Concatenate with separator
local t = {"apple", "banana", "orange"}
local result = table.concat(t, ", ")
engine.print(result) --apple, banana, orange
--Concatenate with space separator
local words = {"Hello", "World"}
local result = table.concat(words, " ")
engine.print(result) --Hello World
--Concatenate subset of table
local t = {"a", "b", "c", "d", "e"}
local result = table.concat(t, "-", 2, 4)
engine.print(result) --b-c-d
--Build CSV line
local data = {"John", "25", "Developer"}
local csv = table.concat(data, ",")
engine.print(csv) --John,25,Developer
--Build path
local parts = {"home", "user", "documents"}
local path = "/" .. table.concat(parts, "/")
engine.print(path) --/home/user/documents

On this page