我在Lua编程,到目前为止,我有这个。
S=tostring(M[i].AllSegmentsList) --it returns "MSH, PID"
for i in string.gmatch(S, ",") do --I have ", " as delimiter
t= {} --Now, I want the values returned by delimiter to be added into an array.
end
我该怎么做。
答案 0 :(得分:3)
之前声明表,并在循环中添加元素,如下所示:
local t = {}
for i in S:gmatch("([^,%s]+)") do
t[#t + 1] = i
end
模式[^,%s]+
匹配一个或多个非逗号,非空格字符。