Click here to Skip to main content
Click here to Skip to main content

A Generic Diff/Patch Utility written in C#

, 27 May 2009
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)

About the Author

kevin delafield

United States United States
No Biography provided

Comments and Discussions

 
GeneralMy vote of 2 Pinmembergam6it28-Jul-11 22:33 
GeneralSeems very similar to another one. PinmemberVladimir Vasiltsov17-Feb-10 10:03 
GeneralFile Formats PinmemberSCADirector3-Jan-08 8:54 
QuestionDid you test this??? PinmemberDARKHalf4-Feb-07 1:41 
AnswerRe: Did you test this??? PinmemberAutoDeveloper17-May-07 3:05 
QuestionRe: Did you test this??? Pinmembermrwizard82d126-Jul-07 17:42 
AnswerRe: Did you test this??? Pinmemberkevin delafield27-May-09 22:27 
GeneralRe: Did you test this??? Pinmembermrwizard82d128-May-09 4:42 
GeneralMore Information PinmemberSteve Hansen24-Aug-06 22:25 
GeneralRe: More Information Pinmemberdiilbert25-Aug-06 2:30 
GeneralRe: More Information PinmemberSteven Roebert25-Aug-06 11:10 
GeneralRe: More Information PinmemberPIEBALDconsult15-Dec-06 3:34 
GeneralRe: More Information Pinmemberkevin 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 | Mobile
Web04 | 2.8.140721.1 | Last Updated 28 May 2009
Article Copyright 2006 by kevin delafield
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid