tags:

views:

128

answers:

3

I'm looking for a diff algorithm that will produce results like SO's edit revisions page. I've more or less just started looking and I'm not opposed to doing it myself but I don't need to reinvent the wheel.

I'll be using C# 4.0. I'll basically have two strings, and old one and a new one. I want to know what has changed in the new one by highlighting and strike throughs.

+3  A: 

Usually implemented with a longest common substring algorithm. This post will be of interest.

spender
Its not longest common **substring** but longest common **subsequence**. A substring is always continuous but a subsequence need not be. The changes made to old text to get new text need not be on consecutive characters.
codaddict
+1  A: 

Its based on Longest common subsequence algorithm, popularly known as LCS.

LCS of old text and new text gives the part that has remain unchanged. So the parts of old text that is not part of LCS is the one that got changed.

From the wiki page above:

It is a classic computer science problem, the basis of diff (a file comparison program that outputs the differences between two files), and has applications in bioinformatics.

codaddict
+1  A: 

You can take a look at Menees Diff for an example written in C#.

cfeduke