Solved

Compare 2 .txt File

Posted on 2006-06-26
2
192 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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