Solved

Compare 2 .txt File

Posted on 2006-06-26
2
193 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
How to debug For loops? 3 71
Tembedded WB animatid gifs not animated on some pcs 2 89
RESTRequest Parameter 4 76
Slow Restore if incremental backups using RDiff.exe 4 48
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
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…

736 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