local function loadCsv(s)local i, j, q, t, r = 1, 1, 0, {}, {}while true dolocal b = s:byte(j)j = j + 1if b == 0x22 then -- 0x22:'"'if q ~= 0 thenq = 3 - qelseif i + 1 == j theni, q = j, 1endelseif q ~= 1 and (b == 0x2c or b == 13 or b == 10) or not b then -- 0x2c:','if b == 0x2c or i + 1 < j or #t > 0 thenlocal c = s:sub(i, j - (q == 2 and s:byte(j - 2) == 0x22 and 3 or 2))if q == 2 thenc = c:gsub('""', '"')endt[#t + 1] = cif b ~= 0x2c thenr[#r + 1] = tt = {}endendif not b thenreturn rendi, q = j, 0endendendlocal f = io.open("test.csv","rb")local s = f:read "*a"f:close()local r = loadCsv(s) -- loadCsv '\r"""a",a",,"""a""",a"b,\r\n,\r\n\n'for _, t in ipairs(r) dofor _, s in ipairs(t) doio.write('[', s, '] ')endprint()endprint("--- " .. #r)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。