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 without a separator
local t = {"hello", "world", "lua"}
local result = table.concat(t)

engine.print("info", result) --'helloworldlua'
Concatenate elements with a separator
local t = {"apple", "banana", "orange"}
local result = table.concat(t, ", ")

engine.print("info", result) --'apple, banana, orange'
Concatenate elements with a space separator
local words = {"Hello", "World"}
local result = table.concat(words, " ")

engine.print("info", result) --'Hello World'
Concatenate a subset of the table
local t = {"a", "b", "c", "d", "e"}
local result = table.concat(t, "-", 2, 4)

engine.print("info", result) --'b-c-d'
Build a CSV line from a table
local data = {"John", "25", "Developer"}
local csv = table.concat(data, ",")

engine.print("info", csv) --'John,25,Developer'
Build a file path from parts
local parts = {"home", "user", "documents"}
local path = "/" .. table.concat(parts, "/")

engine.print("info", path) --'/home/user/documents'

On this page