如何从 LUA 中的字符串中获取数字?

how to get numbers from string in LUA?

我有字符串“0,0,0,-58.43083113,”

我怎样才能用 LUA 得到所有 4 个数字的两倍?谢谢!

我试过 string.match()。但是没用。

local text = "0,0,0,-58.43083113,,"

local numbers = {}
text:gsub("[^,]+", function (str) table.insert(numbers, tonumber(str)+.0) end)
print(table.concat(numbers, ", "))

for str in text:gmatch("[^,]+") do
  table.insert(numbers, tonumber(str) + .0)
end

当然,这是假设您的字符串中只有数字表示和逗号。