954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?

Text file manipulation

0
By Daaave on Jun 5th, 2005 7:42 am

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;

{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
Newbie Poster
5 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

{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
Newbie Poster
5 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

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!

Deffcon
Newbie Poster
1 post since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You