1
나는 루아에서 스크립트를 가지고 있으며, 변수 res를 출력해야하지만이 프린트를 어떻게 해야할지 모르겠습니다. 나는 결과를 인쇄하고 싶었다루아에서 프린트 테이블
function parseCSVLine(line)
local res = {}
local pos = 1
local sep = ','
while true do
local c = string.sub(line,pos,pos)
if (c == "") then break end
if (c == '"') then
-- quoted value (ignore separator within)
local txt = ""
repeat
local startp,endp = string.find(line,'^%b""',pos) -- Digitos
txt = txt..string.sub(line,startp+1,endp-1)
pos = endp + 1
c = string.sub(line,pos,pos)
if (c == '"') then txt = txt..'"' end
-- check first char AFTER quoted string, if it is another
-- quoted string without separator, then append it
-- this is the way to "escape" the quote char in a quote. example:
-- value1,"blub""blip""boing",value3 will result in blub"blip"boing for the middle
until (c ~= '"')
table.insert(res,txt)
-- assert(c == sep or c == "")
pos = pos + 1
else
-- no quotes used, just look for the first separator
local startp,endp = string.find(line,sep,pos)
if (startp) then
table.insert(res,string.sub(line,pos,startp-1))
pos = endp + 1
else
-- no separator found -> use rest of string and terminate
table.insert(res,string.sub(line,pos))
break
end
end
end
return res
end
여기에 예를
local result = parseCSVLine(line)
인쇄 내가하고 싶었던 다른 함수에서 함수의 결과를 얻을
parseCSVLine
에서