我需要将一个字符串拆分并存储到数组中。在这里,我使用了string.gmatch方法,并且它确切地拆分了字符,但我的问题是如何存储到数组中?以下是我的脚本。 我的样本字符串格式:touchedSpriteName = Sprite,10,rose
```lua local str = "touchedSpriteName = Sprite,10,rose" local arr = {} for s in string.gmatch(str, "%w+") do table.insert(arr, s) end ```以上代码将把拆分后的字符串存储在名为“arr”的数组中。
objProp = {}
for key, value in string.gmatch(touchedSpriteName,"%w+") do
objProp[key] = value
print ( objProp[2] )
end
如果我打印(print)objProp,它会给出精确的值。