如何获取一个单词后面的所有文本

目前已有代码:

local msg = "hello hi hey"
local words = {}
for word in msg:gmatch("%S+") do
    table.insert(words, word)
end
-- 将 msg 按空格分割,并将结果存入 words 数组

我想获取 msg 中除第一个单词外的所有文本,并保存为一个变量。我已经知道可以通过 table.remove(words, 1) 来删除第一个单词,但如何将剩下的文本保存为一个变量呢?

点赞
用户10953006
用户10953006

所以使用lua分割为单词的答案

s = "foo bar 123"
words = {}
for word in s:gmatch("%w+") do table.insert(words, word) end

和你的代码:

table.remove(words, 1)

然后你就有了你的结果:

> words[1]
bar
> words[2]
123

编辑:如果你想要连接剩余的字符串:

> words={"test", "123"}
> variable = table.concat(words, " ")
> variable
test 123
> type(variable)
string
>

2021-03-24 01:54:08