Forum > General

Separate text in list format into text file!

(1/1)

Robert W.B.:
I'm trying to separate text in line format in text file, but it does not work!  This is what I'm trying to accomplish.

Date:                Food:            Price:
01-03, 2022    Tomatoes     $1.05
10-03, 2022     Fries             $4.99
15-03, 2022     Bag               $0.50

This is what i looks now!
Date:                Food:            Price:
01-03, 2022    Tomatoes     $1.05
10-03, 2022     Fries         $4.99
15-03, 2022     Bag         $0.50

Is there commands in Pascal that correct this issue?

Thanks in advance.
Bob :(

paweld:
Format function: https://wiki.freepascal.org/Format_function

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  memo1.Lines.Add(Format('%-12s   %-10s   %-8s', ['Date:', 'Food:', 'Price:']));  memo1.Lines.Add(Format('%-12s   %-10s   %8s', ['01-03, 2022', 'Tomatoes', '$1.05']));  memo1.Lines.Add(Format('%-12s   %-10s   %8s', ['10-03, 2022', 'Fries', '$4.99']));  memo1.Lines.Add(Format('%-12s   %-10s   %8s', ['15-03, 2022', 'Bag', '$0.50']));  

Robert W.B.:
Thanks paweld for the help.
I try to se how i can create a textfile with.
for a:=1 to 10 do begin
filewrite(myFile, format('%-12s', intToStr(myVar1[a])+ intToStr(myVar2[a])+intToStr(myVar3[a])  )  );
end;
But it not working! :(
Suggestions paweld?

paweld:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.Button1Click(Sender: TObject);var  tf: TextFile;  i: Integer;begin  AssignFile(tf, 'test_file.txt');  if FileExists('test_file.txt') then    append(tf)  else    rewrite(tf);  for i := 1 to 100 do    writeln(tf, Format('%-13s %-5d   %5d', ['Interation no', i, Random(9999)]));  CloseFile(tf);end;  

Navigation

[0] Message Index

Go to full version