Lua 字符串到表 [英] Lua string to table

查看:33
本文介绍了Lua 字符串到表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串需要作为表格读取

I have a string that I need to read as a table

    notes = "0,5,10,16"

所以如果我需要当前音符的第三个值 10

so if I need the 3rd value of the current notes that is 10

    value = notes[3]

推荐答案

对于示例字符串,你可以这样做

For the example string, you can just do

local notes_tab = {}
for note in notes:gmatch("%d*") do
   table.insert(notes_tab, tonumber(note))
end

这篇关于Lua 字符串到表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆