Click here to Skip to main content
Licence CPOL
First Posted 24 Aug 2006
Views 32,883
Bookmarked 26 times

A Generic Diff/Patch Utility written in C#

By | 27 May 2009 | Article
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

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 2 Pinmembergam6it22:33 28 Jul '11  
GeneralSeems very similar to another one. PinmemberVladimir Vasiltsov10:03 17 Feb '10  
GeneralFile Formats PinmemberSCADirector8:54 3 Jan '08  
QuestionDid you test this??? PinmemberDARKHalf1:41 4 Feb '07  
AnswerRe: Did you test this??? PinmemberAutoDeveloper3:05 17 May '07  
QuestionRe: Did you test this??? Pinmembermrwizard82d117:42 26 Jul '07  
AnswerRe: Did you test this??? Pinmemberkevin delafield22:27 27 May '09  
GeneralRe: Did you test this??? Pinmembermrwizard82d14:42 28 May '09  
GeneralMore Information PinmemberSteve Hansen22:25 24 Aug '06  
GeneralRe: More Information Pinmemberdiilbert2:30 25 Aug '06  
GeneralRe: More Information PinmemberSteven Roebert11:10 25 Aug '06  
Yeh, only an introduction isn't really what you call an article, a bit more info on how and why you implemented this might be nice Wink | ;)
GeneralRe: More Information PinmemberPIEBALDconsult3:34 15 Dec '06  
GeneralRe: More Information Pinmemberkevin delafield22:27 27 May '09  

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.

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