我正在使用文本文件Waiterstips。 文本文件如下所示:
34.12;45.54;67.99;23.01;99.50;15.14;96.12;
65;67;89;45;00.00;15.23;12.15;00.00;95.32;
87;87;65;97;41.25;36.58;96.14;78.88;11.01;
67;54;57;37;00.00;00.00;10.20;05.00;12.41;
When I use the code below the text file look like this:
10.00;45.54;67.99;23.01;99.50;15.14;96.12
65.00;67.00;89.00;12.50;10.00;15.23;12.15
87.00;87.00;65.00;97.00;41.25;36.58;96.14
67.00;54.00;57.00;50.12;10.00;10.00;10.20
;;;;;;
请帮助我想保存数据,就像我读它时一样。我不想要;;;;最后。
procedure TForm1.BitBtn2Click(Sender: TObject);
var
fFile : TextFile;
iCount : Integer;
begin
AssignFile(fFile, 'Waiterstips.txt');
Rewrite(fFile);
For iCount := 1 to StringGrid1.RowCount - 1 do
begin
Writeln(fFile, StringGrid1.Cells[1,iCount]+ ';'+ StringGrid1.Cells[2,iCount]+ ';' +
StringGrid1.Cells[3,iCount]+ ';' +StringGrid1.Cells[4,iCount]+ ';' +StringGrid1.Cells[5,iCount]
+ ';' +StringGrid1.Cells[6,iCount]+ ';'+StringGrid1.Cells[7,iCount]+ ';');
end;
CloseFile(fFile);
end;
答案 0 :(得分:4)
显然,TStringGrid
的末尾有一个空白行。
您可以在写出之前检查行内容来修复它:
for iCount := 1 to StringGrid1.RowCount - 1 do
begin
if StringGrid1.Cells[1, iCount] <> '' then
WriteLn(fFile, StringGrid1.Cells[1, iCount] + ';' +
StringGrid1.Cells[2, iCount] + ';' +
.....
end;