table.concat()

类型 函数
table.*
返回值 字符串
修订 发行版 2024.3703
关键字 table 数组
另请参见 table.insert()

概述

将表中的元素连接在一起以形成一个字符串。每个元素都必须能够强制转换为字符串。可以指定一个分隔符,该分隔符置于连接的元素之间。

语法

table.concat( t )

table.concat( t, sep )

table.concat( t, sep, i )

table.concat( t, sep, i, j )
t (必需)

数组其中所有元素都是字符串或数字的数组。

sep (可选)

字符串要在连接的表值之间插入的字符串。默认值为空字符串。

i (可选)

数字要连接的第一个表索引。默认值为 1。

j (可选)

数字要连接的最后一个表索引。默认值为数组 t 的长度。如果 i 大于 j,则返回空字符串。

示例

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