2006/6/5, Tony Pelton <[EMAIL PROTECTED]>:
On 6/5/06, Alexandre Leclerc <[EMAIL PROTECTED]> wrote:
> I checked arround to see if there was a function to parse a valid CSV
> string and return the result in a array?
>
> procedure DecodeCSV(s: string; var a: array of string);
>
> So a string like:
> 123, my name, "name, my", "just ""more"" text"
>
> would return in an array:
> [ '123' , 'my name' , 'name, my', 'just "more" text' ]

i don't know if 'ExtractWord' and 'ExtractWordPos' with a 'Set of Char
= [,]' would help ?

it doesn't do the parsing for you strictly, but makes writing a little
parsing routine _much_ simpler ?

Yes thank you; I did check these functions. In fact the fastest method
for parsing will be like the good old Pos() function and simply have a
PChar and parse the string. The problem is the quote logic. But this
is fine, I'm actually completing a function to parse custom CSV files
(you can define the quote and the value delimiters). The result will
be an array. (In fact, you must pass a variable array... I'm not sure
you can return a dynamic array with a function. I'll check that, and
if it looks good, I'll submit a patch to fpc/strutils if they are
interested to include it.

(And thank you Tony Maro for your reply).

Regards.

--
Alexandre Leclerc

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to