Delphi CSV Parser

Simplify csv file parsing with this handy Delphi class.

Public Interface
TwpsCsvParser = class(TObject)
public
 property IgnoreFirstLine: boolean read FIgnoreFirstLine write FIgnoreFirstLine;
 property Fields: TStrings read FFields;
 property Line: string read FLine;

 procedure Close;
 procedure LoadFromFile(const FileName: string);
 // ReadLn returns true if a line was read; otherwise returns false.
 function  ReadLn: boolean;
end;
      
Sample Code
procedure CsvParserSample;
const
  CsvFileName = 'sample01.csv';
var
  parser: TwpsCsvParser;
  lineCount: integer;
begin
  lineCount := 0;
  parser := TwpsCsvParser.Create;
  try
    parser.LoadFromFile(CsvFileName);
    while parser.ReadLn do
    begin
      Writeln(parser.Fields[0]);
      Inc(lineCount);
    end;
  finally
    parser.Close;
  end;
end;
      

Warranty

WPS Delphi Library software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

License

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the certain restrictions (see individual source code files for restrictions).

About White Peak Software | Site Map | Privacy Policy
Copyright © 2003-2008 White Peak Software Inc. All rights reserved.