Delphi/CB
•  Greatis •  Security •  AppDatabase •  Utilities •  Visual Basic • .NET •  just4fun
Delphi / C++ Builder
Components, utilities and tips for Delphi and C++ Builder developers
Hot Offer
Save your money!
Featured
Ultimate Pack  hot!
Image Editor  new!
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET

...get more...
for Delphi.NET, C#, VB.NET
for Delphi VCL, BCB 3-6

News Tips .NET Software VCL Software Partners  

Compare two files of txt format
We will read strings from each file while each of files has a data.
And we will compare each string from the first file with corresponding string from the second file.
All differences we will write in a memo.

procedure TForm1.Button1Click(Sender: TObject);
var
  First, Second: TextFile;
  Str, Str2: string;
begin
  Memo1.Clear;
  if (Edit1.Text<>'')and(Edit2.Text<>'') then
  begin
    AssignFile(First, Edit1.Text);
    AssignFile(Second, Edit2.Text);
    Reset(First);
    Reset(Second);
    while not EOF(First) do
    begin
      if EOF(Second)=True then
      begin
        Memo1.Lines.Add('*** ATTENTION ***');
        Memo1.Lines.Add('SECOND file has finished
                         but FIRST file has had a data yet.');
        Break;
      end;
      Readln(First, Str);
      Readln(Second, Str2);
      if CompareStr(Str, Str2)<>0 then
      begin
        Memo1.Lines.Add('FIRST  - '+Str);
        Memo1.Lines.Add('SECOND - '+Str2);
        Memo1.Lines.Add(' ');
      end;
    end;
    if EOF(Second)=False then
    begin
      Memo1.Lines.Add('*** ATTENTION ***');
      Memo1.Lines.Add('FIRST file has finished
                       but SECOND file has had a data yet.');
    end;
    CloseFile(First);
    CloseFile(Second);
    if Memo1.Lines.Count=0 then
      Memo1.Lines.Add('FIRST file is identical to SECOND file');
  end;
end;

Related topics
Compare string with pattern
Comparing of two strings

For more
Delphi Help

Download source


Our Partner
DevArchive.com
Recommended
just4fun
Useful Resources
Win32.hlp Online
Unix Manual Pages
MegaDetailed.NET
in3steps.com
Newsletters
Subscribe to our news!    Subscribe to our news!


Greatis Software Greatis | Security | AppDatabase | Utilities | Delphi/CB | Visual Basic | .NET | just4fun

Contacts | Add to Favorites | Recommend to a Friend | Privacy Policy | Copyright © 1998-2008 Greatis Software