[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Code Request: CSV parser written in Lua
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 22 Nov 2000 21:42:22 -0200 (EDT)
>Does anyone have a nice piece of Lua code that would parse a CSV (Comma
>Separated Values) file ?
To parse a general CSV file, in which commas may appear inside quoted strings,
is hard to do in a "natural" way in Lua, ie, using gsub or strfind.
(I think Roberto tried to do this once.)
I can't see any other way than doing a character-by-character parsing.
If there are no quoted strings, or no commas inside quoted strings, then it's
simple. Something like
local t={}
gsub(s..",","([^,]*),",function (x) tinsert(%t,x) end)
--lhf