Matt
--
With best regards, Mike Shkolnik
E-mail: mshk...@scalabium.com
WEB: http://www.scalabium.com
"matthew" <n...@email.com> wrote in message
news:41db028f$1...@newsgroups.borland.com...
> I am wondering how to parse a csv file with delphi?
You can load csv files into a number of components by default I
believe, or parsee through it yourself with pos and copy :)
Assuming a tab delimited file.
var f : textfile;
l : tstringlist;
s : string;
...
assignfile(f, 'myfile.txt');
reset(f);
l := tstringlist.create;
l.delimiter := #9;
while not eof(f) do begin
readln(f, s);
// the instruction below needed only if you have embedded blanks
s := StringReplace(s, ' ', ' _', [ftReplaceAll]);
l.DelimitedText := s;
at this point, the tstringlist contains the fields in your original string.
You will have to replace the _ back to spaces on each line, if needed. This
bit is required because delimitedtext will break not only on tab but also
when finding a space.
Robert
> I am wondering how to parse a csv file with delphi?
Assuming its not too huge you can load a file into a TStringList using the
LoadFromFiles method. You can then use a second TStringList to parse each
line into individual items - just assign the second list's CommaText
property from one of the lines in the first list.
If more parsing than this is needed let us know what you're trying to do!
HTH,
--
Ian