Click to See Complete Forum and Search --> : Text version compare algorithm


trond-eirik
August 2nd, 2000, 03:28 AM
Hello

Does anyone know about a good algorithm to compare to versions of a text document?
I want a in-view present, where deleted text are for example gray, and new text are for example blue.
If you copy the lines of code below into a html page, it should give a visible view of what I'm looking for.
Almost the same as the "Track Changes" function in word, except that I want to compare to existing files.
<p>
<b>Old text:</b> This is the old text. As you see it is not a long text.
</p>
<p>
<b>New text:</b> This is the new text. As you see it is not a long text. But it have things added and removed.
</p>
<p>
<b>Diff view:</b> This is the <font color='gray'>old</font><font color='blue'>new</font> text. As you see it is not a long text. <font color='blue'>But it have things added and removed.</font>

Saeed
August 2nd, 2000, 06:37 PM
Writing up such program is not very difficult .
Using some String classes (CString) or if you are using Basic..there are plenty of string manipulation functions that one could use...
I would say roll up your sleeves and D.I.Y.
Regards

kevin_Wn
August 10th, 2001, 03:26 AM
I have a feeling that it will not be so easy to do.
Perhaps using strstr() frequently will be useful.
Good luck!

Manish Malik
August 19th, 2001, 11:24 AM
Hello,

I can suggest an approach. This will require you to consider your text sentence-by-sentence (otherwise the search routine will become bulky).

Lets say you have two sentences:

1: abc def ijk lmn opq.
2: abc xyz def imn opq.

Now start with first word of 1 - abc. Search this word in whole of 2. If you find it as the first word of 2, then add it as "same". Now take the second word - def. Search for this word in 2. This doesn't exist at second position, but third, mark the second word of 2 as "new" (xyz) and mark "def" as "same".
Now you have the following table:

abc(same) xyz(new) def(same)......and so on.

You can assign colour codes to each as and when required.

Similarly you can check for deletions, etc.

Hope this helps a bit.

Reply back to tell us how you did it. :-)