🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.language.objectpascal
1 messages
1 total messages Started by cloudzero Thu, 18 Nov 2004 12:15
Help needed with text file processing problem.
#32
Author: cloudzero
Date: Thu, 18 Nov 2004 12:15
54 lines
2591 bytes
Hi gang,
After a very long absence from programming, I've been persuaded to
build a text processing program.  I've come up against a sticky little
problem that I hope you can help on.

This routine is expected to read and create two text files.  The
primary file is the original file containing perhaps several tens of
thousand lines.  The secondary file contains a shorter list of lines.

This routine needs to read the primary file a line at a time, and
compare it to lines found in the in the secondary file.  If the line
in the secondary is found in a line in the primary file, it needs to
output the quarantine file, otherwise, it needs to output to the
target file.  I have tried several incarnations of the code below with
varying degrees of failure.

I'm sure I'm missing something really fundamental and yes I know I can
shorten a few lines..

Thanks in advance.

begin
	// original source text file      
	AssignFile(sourcefile, PrimaryDialogue.filename);  
	Reset(sourcefile);
	
	// output file with lines containing banned word
	assignFile(quarantined, 'quarantined.txt');    
	rewrite(quarantined);
	
	// remaining lines
	assignFile(targetfile, savedialogue.FileName);
	rewrite(targetfile);
	while not EOF(sourcefile) do begin
		readln(sourcefile, buffer2);
		
		// text file containing list of banned words.
		AssignFile(blacklist, SecondaryDialogue.filename);
		Reset(blacklist);
		while not EOF(blacklist) do begin
			readln(blacklist, buffer);
			textpos:=pos((buffer2),(buffer));
			if textpos <> 0 then
				Writeln(quarantined, buffer2)
			else
				Writeln(targetfile, buffer2);
			end; // if
		end; // while
	end; // while
end; // if
closefile(sourcefile);
CloseFile(targetfile);
CloseFile(blacklist);
CloseFile(quarantined);
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads