Article View: borland.public.delphi.language.objectpascal
Article #32Help needed with text file processing problem.
From: cloudzero
Date: Thu, 18 Nov 2004 12:15
Date: Thu, 18 Nov 2004 12:15
54 lines
2591 bytes
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);
Technical Details
Message-ID:
<1903e0c9.0411180415.35cb27cf@posting.google.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 109d30,d88788042ff8a18b,start X-Google-Attributes: gid109d30,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!not-for-mail From: reborndelphi@cloudzero.co.uk (cloudzero) Newsgroups: borland.public.delphi.language.objectpascal Subject: Help needed with text file processing problem. Date: 18 Nov 2004 04:15:23 -0800 Organization: http://groups.google.com Lines: 54 Message-ID: <1903e0c9.0411180415.35cb27cf@posting.google.com> NNTP-Posting-Host: 62.255.64.7 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1100780123 7601 127.0.0.1 (18 Nov 2004 12:15:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 18 Nov 2004 12:15:23 +0000 (UTC)