C# .NET - Compare two paragraphs and highlight the differences

Asked By kalyan on 24-Dec-12 08:19 AM
Hi,
Greetings for the day.

I have two div's which contains some text in them.The thing I required to do is to compare the text in both div's and highlight the differences and the comparision should be done word by word.

For example,
Tthe two div's contains text as follows:
In div1, 'Hi, Good Morning'
In div2, 'Hi, Very Good Morning'

So, the text in div2 should be like 'Hi, Very Good Morning' and div1 is as it is.

And another scenario is:
In div1, 'Hi, Good Morning to all'
In div2, 'Hi, Good Morning to everyone'

Then the text should be like.
div1, 'Hi, Good Morning to all'

div2, 'Hi, Good Morning to everyone'


Could you please help me how to do this in C#.

Thanks in Advance,
Hima Kalyan.
Robbe Morris replied to kalyan on 24-Dec-12 09:34 AM
You can break this up into pieces by using the string .Split function

var lines = mytext.Split(Environment.NewLine);
var words = mytext.Split(" ".ToCharArray());

Iterate through these two arrays looking for differences.
kalyan replied to Robbe Morris on 26-Dec-12 12:29 AM
Could you please provide me the code for that...actually I'm running out of time, so I am requesting for the code.

Thanks in Advance for the help