Skip to content

Instantly share code, notes, and snippets.

@9bic
Last active August 29, 2015 14:14
Show Gist options
  • Save 9bic/c2a4473994abaeeef613 to your computer and use it in GitHub Desktop.
Save 9bic/c2a4473994abaeeef613 to your computer and use it in GitHub Desktop.
DiffMatchPatch in C#
var left = "hoge";
var right = "hoge2";
var dmp = new DiffMatchPatch.diff_match_patch();
var result = dmp.diff_main(left, right);
// as HTML string
var html = dmp.diff_prettyHtml(result);
// as Object
foreach(var entry in result) {
if(entry.operation == DiffMatchPatch.Operation.DELETE) {
Console.WritLline("DELETE:{0}", entry.text);
}
if(entry.operation == DiffMatchPatch.Operation.INSERT) {
Console.WriteLine("INSERT:{0}", entry.text);
}
if(entry.operation == DiffMatchPatch.Operation.EQUAL) {
Console.WriteLine("EQUAL:{0}", entry.text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment