Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含数字行和列的 data.txt,我想将其内容存储到二维数组中。所以基本上我正在寻找如何将对象从文件读取分配到二维数组。顺便说一句,我正在使用 LUA,只是一个新手。
请帮忙!提前致谢。
local mt = {} -- create the matrix for line in io.lines'datafile.txt' do local new_row = {} for n in line:gmatch'%S+' do table.insert(new_row, tonumber(n)) end if #new_row > 0 then table.insert(mt, new_row) end end
此代码将默默地跳过所有非数字单词。