Home > Back-end >  Delphi how to read the CSV format
Delphi how to read the CSV format

Time:11-16

Masters, for help how to read and write using delphi5 CSV file, thank you

EG.
The NAME AGE LIVE IN_DATE OUT_DATE
'CHOW', '27', 'CHINA', '28-04-2011', '28-04-2012'

CodePudding user response:

CSV is usually a comma-separated value of text files, also some separators are specified characters,
Read it, therefore, can be read by the text file, line by line processing:

 
Procedure TForm1. Btn1Click (Sender: TObject);
Var sFile, sLine: TStrings;
R, c: Integer;
The begin
SFile:=TStringList. Create;
SFile. LoadFromFile (' d: \ 1. TXT);
SLine:=TStringList. Create;
For r:=0 to sFile. Do the begin the Count - 1
SLine.Com maText:=sFile [r].
For c:=0 to sLine. Do the begin the Count - 1
Mmo1. Lines. The Add (sLine [c]);
end;
end;
SLine. Free;
SFile. Free
end;
  • Related