Click here to Skip to main content
11,583,532 members (65,055 online)
Click here to Skip to main content

A Generic Diff/Patch Utility written in C#

, 27 May 2009 CPOL 40.6K 512 27
Rate this:
Please Sign up or sign in to vote.
Generic Diff/Patch Utility written in C#

Download Diff2.zip - 7.82 KB

Introduction

Have you ever wanted or needed a diff utility optimized for the .NET platform.

This article provides an implementation of a diff utility written in C#.

It operates over generics, so you can provide lists of anything to be diffed or patched,
including strings (such as lines from files), int, objects, or even bytes.

Example of using the Diff class to diff 2 text files

List<string> a = new List<string>();

List<string> b = new List<string>();

StreamReader fs1 = new StreamReader(argv[0]);

StreamReader fs2 = new StreamReader(argv[1]);

string line;

while ((line = fs1.ReadLine()) != null)

{

    a.Add(line);

}

while ((line = fs2.ReadLine()) != null)

{

    b.Add(line);

}

fs1.Dispose();

fs2.Dispose();

Item[] diff_items = Diff2.Diff<string>(a.ToArray(), b.ToArray());

This performs the diff. The final parameter indicates whether the actual differences should be included in the edit script when the diff is performed.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

kevin delafield
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 2 Pin
gam6it28-Jul-11 22:33
membergam6it28-Jul-11 22:33 
GeneralSeems very similar to another one. Pin
Vladimir Vasiltsov17-Feb-10 10:03
memberVladimir Vasiltsov17-Feb-10 10:03 
GeneralFile Formats Pin
SCADirector3-Jan-08 8:54
memberSCADirector3-Jan-08 8:54 
QuestionDid you test this??? Pin
DARKHalf4-Feb-07 1:41
memberDARKHalf4-Feb-07 1:41 
AnswerRe: Did you test this??? Pin
AutoDeveloper17-May-07 3:05
memberAutoDeveloper17-May-07 3:05 
QuestionRe: Did you test this??? Pin
mrwizard82d126-Jul-07 17:42
membermrwizard82d126-Jul-07 17:42 
AnswerRe: Did you test this??? Pin
kevin delafield27-May-09 22:27
memberkevin delafield27-May-09 22:27 
GeneralRe: Did you test this??? Pin
mrwizard82d128-May-09 4:42
membermrwizard82d128-May-09 4:42 
GeneralMore Information Pin
Steve Hansen24-Aug-06 22:25
memberSteve Hansen24-Aug-06 22:25 
GeneralRe: More Information Pin
diilbert25-Aug-06 2:30
memberdiilbert25-Aug-06 2:30 
GeneralRe: More Information Pin
Steven Roebert25-Aug-06 11:10
memberSteven Roebert25-Aug-06 11:10 
GeneralRe: More Information Pin
PIEBALDconsult15-Dec-06 3:34
memberPIEBALDconsult15-Dec-06 3:34 
GeneralRe: More Information Pin
kevin delafield27-May-09 22:27
memberkevin delafield27-May-09 22:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 28 May 2009
Article Copyright 2006 by kevin delafield
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid