Solved

Compare 2 .txt File

Posted on 2006-06-26
2
189 Views
Last Modified: 2010-04-05
Hello All;

  I need to look at the following 2 files loaded in "2" RichEdit's

one.txt
========
something
someting
else
goes
here
today
toay

---------
two.txt
========
someting
else
goes
here
toay

--------------

After the comparison.
I need to have the Results loaded into a 3rd Richedit.

The results need to be the words that "Do Not" match the "one.txt" entries.

one.txt   ---> Good
twn.txt   ---> Compare for Good

RichEdit3   ---> Takes the words that "DO Not" Compare to "one.txt"
(Think I already mentioned that one : )  Just wanted to make sure you all understand what I am needing).

I found a few articles here on EE that resemble this, but not really.
Like this one that uses TListBox   http:Q_20799616.html
But, I do not think that is what I am needing.

Any idea's (or) code for something like this would be really appreciated.

Carrzkiss
0
Comment
Question by:Wayne Barron
2 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 250 total points
ID: 16989583
Wayne,

Give the following a try. It uses richedit1 as the white list (good words), richedit2 as the list to check, and richedit3 as the resulting black list (those that don't match items in richedit1).

Regards,
Russell

---

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, RegExprEx, ComCtrls;

type
  TForm1         =  class(TForm)
     Label1:     TLabel;
     Label2:     TLabel;
     Label3:     TLabel;
     Button1:    TButton;
     RichEdit1:  TRichEdit;
     RichEdit2:  TRichEdit;
     RichEdit3:  TRichEdit;
     procedure   Button1Click(Sender: TObject);
  private
     // Private declarations
  public
     // Public declarations
  end;

var
  Form1:         TForm1;

implementation
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var  listBad:       TStringList;
     listGood:      TStringList;
     dwIndex:       Integer;
     dwFind:        Integer;
begin

  // Create list to hold bad words
  listBad:=TStringList.Create;
  try
     // Make sure list is sorted and ignores duplicates
     listBad.Sorted:=True;
     listBad.Duplicates:=dupIgnore;
     // Create list to hold good words
     listGood:=TStringList.Create;
     try
        // Get the good list
        listGood.Assign(RichEdit1.Lines);
        // Sort the list
        listGood.Sort;
        // Lock the list to compare
        RichEdit2.Lines.BeginUpdate;
        try
           // Walk the list to compare
           for dwIndex:=0 to Pred(RichEdit2.Lines.Count) do
           begin
              // Check against the good list
              if not(listGood.Find(RichEdit2.Lines[dwIndex], dwFind)) then
              begin
                 // Not found in good list
                 listBad.Add(RichEdit2.Lines[dwIndex]);
              end;
           end;
        finally
           // Unlock compare list
           RichEdit2.Lines.EndUpdate;
        end;
        // Update the bad list
        RichEdit3.Lines.Assign(listBad);
     finally
        // Free good list
        listGood.Free;
     end;
  finally
     // Free bad list
     listBad.Free;
  end;

end;

end.

--- dfm ---

object Form1: TForm1
  Left = 188
  Top = 229
  Width = 589
  Height = 330
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poScreenCenter
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 12
    Top = 12
    Width = 57
    Height = 13
    Caption = 'Good words'
  end
  object Label2: TLabel
    Left = 200
    Top = 12
    Width = 140
    Height = 13
    Caption = 'Compare against good words'
  end
  object Label3: TLabel
    Left = 388
    Top = 12
    Width = 30
    Height = 13
    Caption = 'Result'
  end
  object Button1: TButton
    Left = 12
    Top = 260
    Width = 75
    Height = 25
    Caption = 'Process'
    TabOrder = 0
    OnClick = Button1Click
  end
  object RichEdit1: TRichEdit
    Left = 12
    Top = 28
    Width = 181
    Height = 225
    Lines.Strings = (
      'something'
      'someting'
      'else'
      'goes'
      'here'
      'today'
      'toay')
    TabOrder = 1
  end
  object RichEdit2: TRichEdit
    Left = 200
    Top = 28
    Width = 181
    Height = 225
    Lines.Strings = (
      'someting'
      'else'
      'goes'
      'here'
      'toay'
      'bad word')
    TabOrder = 2
  end
  object RichEdit3: TRichEdit
    Left = 388
    Top = 28
    Width = 181
    Height = 225
    TabOrder = 3
  end
end



0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 16990153
Runs Great!!!
As I expected coming from you Mr. Russell.

Once I get the opertunity, I am going to go through your Class files
And see what makes your code work the way that it does.
And hopefully, send you something over that will "maybe" surprise you.

Take Care and Thank you once again for your great Delphi Programming.

Wayne
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now