Solved

Compare 2 .txt File

Posted on 2006-06-26
2
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 31

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

691 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