创建Lua函数载入CSV文件并保存到表中的函数:
function GetLines(fileName) indx = 0 myLines ={} for line in io.line(string.format("%s%s", "c:/lua_scripts/",filename)) do indx = indx + 1 myLines[indx] = line end return indx, myLines --returns number of lines and line table end function GetValues(myString) num = 0 values = {} if myString ~= nil then while string.find(myString, ",") ~= nil do i, j =string.find(myString, ","); num =num + 1; values[num] = string.sub(myString, 1, j-1); myString = string.sub(myString, j+1, string.len(myString)) end num = num + 1 values[num] = myString end return num, values end
Lua读取CSV文件到table中
时间: 2024-11-06 16:27:45