我有一串由空格分隔的数字,我需要将它们存储在表中,但由于某种原因,负号不会被识别。带负号的数字的正确模式是什么?
cord = "-53 2 -21"
map = {}
for num in cord:gmatch("%w+") do
table.insert(map, num)
end
map[1], map[2], map[3] = tonumber(map[1]), tonumber(map[2]), tonumber(map[3])
print(map[1])
print(map[2])
print(map[3])
这是输出我得到:
53
2
21
我认为这个问题是我使用的模式,我应该怎么改?
'[ - %d] +'匹配'123-456' ... – lhf 2014-10-29 12:45:21