Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use google-diff-match-patch C# library?

Tags:

I am looking at http://code.google.com/p/google-diff-match-patch/ and have downloaded the file. When I look at it is 2 files

DiffMatchPatch.cs DiffMatchPatchTest.cs 

When I try to make a new object of DiffMatchPatch.cs I have to pass in some operation and string text.

http://neil.fraser.name/software/diff_match_patch/svn/trunk/demos/demo_diff.html

In the demo they cross out the words that are different and that is what I am trying to achieve.

I am trying to compare 2 blocks of text on the server side finds the differences and send a email to the user with the file block of text to them like the end result is in the demo that I posted above.

So does anyone have a tutorial on how to use the C# version?

like image 842
Sharpoint Avatar asked May 18 '11 22:05

Sharpoint


2 Answers

For reference, this is really easy:

var dmp = new diff_match_patch(); var diffs = dmp.diff_main(text1, text2); var html = dmp.diff_prettyHtml(diffs); 
like image 176
ChrisR Avatar answered Sep 24 '22 08:09

ChrisR


Implementation with current version(2.1.0) would look like this

var dmp = DiffMatchPatchModule.Default; var diffs = dmp.DiffMain(text1, text2); var html = dmp.DiffPrettyHtml(diffs); 
like image 37
maxlego Avatar answered Sep 24 '22 08:09

maxlego