Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Diff Algorithm for Text [closed]

Tags:

c#

algorithm

diff

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.

like image 756
Molly Avatar asked Sep 21 '10 20:09

Molly


1 Answers

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.

like image 185
codaddict Avatar answered Oct 23 '22 13:10

codaddict