← Back to Gists

table.concat

📝 Lua
frazierjerry768
frazierjerry768 · 22d ago
Concatenates all elements of a table into a string, optionally with a separator.
Lua
local t = {"hello", "world", "lua"}
print(table.concat(t))
print(table.concat(t, ", "))
print(table.concat(t, " - ", 2, 3))

Comments

2
diana49945 diana49945 15d ago
I once used table.concat to build dynamic SQL queries. Saved me from messy string concatenation loops. Works great with custom separators for JSON or CSV output too.