Difference algorithm in C# to find the changes between two different versions of a piece of text.

sachinjain_aspnet used Ask the Experts™
I need to implement a Difference algorithm in C# or Vb.net to find the changes between two different versions of a piece of text.

I have used the c# version on codeproject and its really good for what I wanted...


but in this code I am only getting the "Character Wise Difference" feature. But the one for which I am looking is "word wise difference" similar what you must have seen a wiki page does
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Difference algoritm has to work on character-to-character comparison to find the changed characters.

Now the kind of difference algo you are searching is for showing extra data (line) deleted/changed/added to previous text.

I suggested algo would be:
1. Read the text (both the files) and break it into paragraphs or technically split by \r\n chara
2. Now for each paragraphs try to from one file (source) to other file (destination) -- excluding the paragraphs which are matched.
3. Now the rest are unmatched paragraphs. These may be added or deleted or modified ones.

Hope this helps :)
Well, I have found the solution through javascript. Following is the link

how this is different from character-to-character comparison ?


Well i want the code for word comparison. so say if i change word good to bad.. the algo should show that i ahve changed the word not complete line or paragraph which is this algo is doing correctly
ok...you can go ahead and close the question

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial