Click here to Skip to main content
6,634,665 members and growing! (16,417 online)
Email Password   helpLost your password?
General Programming » Algorithms & Recipes » General     Intermediate License: The Code Project Open License (CPOL)

A Generic Diff/Patch Utility written in C#

By kevin delafield

Generic Diff/Patch Utility written in C#
C# 2.0, Windows, .NET 2.0VS2005, Dev
Version:5 (See All)
Posted:24 Aug 2006
Updated:27 May 2009
Views:22,177
Bookmarked:24 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
12 votes for this article.
Popularity: 1.94 Rating: 1.80 out of 5
8 votes, 66.7%
1

2

3

4
4 votes, 33.3%
5

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


Member

Location: United States United States

Other popular Algorithms & Recipes articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 11 of 11 (Total in Forum: 11) (Refresh)FirstPrevNext
GeneralFile Formats PinmemberSCADirector9:54 3 Jan '08  
GeneralDid you test this??? PinmemberDARKHalf2:41 4 Feb '07  
GeneralRe: Did you test this??? PinmemberAutoDeveloper4:05 17 May '07  
QuestionRe: Did you test this??? Pinmembermrwizard82d118:42 26 Jul '07  
AnswerRe: Did you test this??? Pinmemberkevin delafield23:27 27 May '09  
GeneralRe: Did you test this??? Pinmembermrwizard82d15:42 28 May '09  
GeneralMore Information PinmemberSteve Hansen23:25 24 Aug '06  
GeneralRe: More Information Pinmemberdiilbert3:30 25 Aug '06  
GeneralRe: More Information PinmemberSteven Roebert12:10 25 Aug '06  
GeneralRe: More Information PinmemberPIEBALDconsult4:34 15 Dec '06  
GeneralRe: More Information Pinmemberkevin delafield23:27 27 May '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 27 May 2009
Editor:
Copyright 2006 by kevin delafield
Everything else Copyright © CodeProject, 1999-2009
Web22 | Advertise on the Code Project