Text file manipulation

Daaave 0 Tallied Votes 481 Views Share

This snippet shows how to open, read, write and close text files. This skeleton can be modified to handle any type of file, from untyped to text to typed files.

procedure CopyFile;
var
  F1  : text;
  F2  : text;
  FN1 : string;
  FN2 : string;
begin
FN1 := 'infile.txt';
FN2 := 'outfile.txt';

assign( F1, FN1 );
reset( F1 );  { open file for reading }

assign( F2, FN2 );
rewrite( F2 );  { open file for writing, destroying contents, if any }

while not EOF( F1 ) do
begin
readln( F1 );
{ file manipulation goes here }
writeln( F2 );
end;

close( F1 );
close( F2 );
end;
Yggdrasil 0 Newbie Poster

{Ohayou:: It's better I think not to write:}
readln(F1);
writeln(F2);
{but instead}
read(F1);
write(F2);
{because ..ln moves the pointer to the next line without reading or writing in the same line}

Yggdrasil 0 Newbie Poster

{Ohayou:: It's better I think not to write:}
readln(F1);
writeln(F2);
{but instead}
read(F1);
write(F2);
{because ..ln moves the pointer to the next line without reading or writing in the same line}

Deffcon 0 Newbie Poster

Umm i know it's not exactly in this context and that it's quite harder to achieve but how can i manipulate my text so that it saves the text from MEMO1 into the first column in the file i'm saving the text into and the text from MEMO2 into the same file ...second column? ...I'm looking everywhere for any hints but can't find any.
Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.