【发布时间】:2017-05-18 17:17:35
【问题描述】:
如何在 Lua 中用分号分割字符串?
local destination_number="2233334;555555;12321315;2343242"
在这里我们可以看到分号 (;) 多次出现,但我只需要在第一次出现之前从上面的字符串输出。
尝试过的代码:
if string.match(destination_number, ";") then
for token in string.gmatch(destination_number, "([^;]+),%s*") do
custom_destination[i] = token
i = i + 1
end
end
输出:
2233334
我已经尝试过上面的代码,但是 Lua 脚本的新手,所以无法获得准确的语法。
【问题讨论】:
-
destination_number:gmatch '(%d+);?'。如果您也需要字母,请替换为%w。 -
这里和整个网络都多次询问和解释字符串拆分。
-
如果以下答案之一对您有用,请采纳。