hotmailisforloosers
Programmer
Okay, well I thought I was going to be taken off this task, but I never was...... so I need to fix this process of highlighting the differences between two articles (that line up side by side), modified and the old version.
I went back and basically started over with a different perspective. Now I'm splitting it up by sentences, and just highlighting the entire sentence if there is a difference. I'm actually highlighting where there aren't differences in another color too, for testing purposes.
Where I run into problems is where a sentence is totally deleted, or a whole new one is added..... that throws off the comparison order and causes one insertion or deletion to make the entire rest of the page highlight as changed.
I have been able to get around that some... the code I have now seems to find additions like that, but it totally skips over them... flat out removes them from the text, rather than highlighting a different color. So I think I've made a big step in isolating the differences.... but I can't for the life of me figure out how to keep it from skipping over it like that (or inserting a whole new duplicate string for each sentence).
So I'll paste my code so far here, and maybe an experienced programmer will have a suggestion. Here:
I went back and basically started over with a different perspective. Now I'm splitting it up by sentences, and just highlighting the entire sentence if there is a difference. I'm actually highlighting where there aren't differences in another color too, for testing purposes.
Where I run into problems is where a sentence is totally deleted, or a whole new one is added..... that throws off the comparison order and causes one insertion or deletion to make the entire rest of the page highlight as changed.
I have been able to get around that some... the code I have now seems to find additions like that, but it totally skips over them... flat out removes them from the text, rather than highlighting a different color. So I think I've made a big step in isolating the differences.... but I can't for the life of me figure out how to keep it from skipping over it like that (or inserting a whole new duplicate string for each sentence).
So I'll paste my code so far here, and maybe an experienced programmer will have a suggestion. Here:
Code:
<%
' Trim off spaces from beginning and end while setting the strings... since they do seem to
' leave a lot of spaces around the article.
R1_old = Trim(Recordset1.Fields.Item("CHarticle").Value) ' Article before modification
R1_new = Trim(Recordset1.Fields.Item("CHarticle2").Value) ' Article after modification
' Disable HTML so that the HTML code doesn't interfere with highlighting, and so that
' admin can see code changes as well........... kills the layout of a page though,
' and is not as easy to look at... you could also remove all tags, or specific tags.
R1_old = Replace(R1_old, "<", "<")
R1_new = Replace(R1_new, "<", "<")
' Splitting the articles up into sentences. artNew and Old become arrays of strings
artNew = Split(R1_new, ".")
artOld = Split(R1_old, ".")
For i = 0 to (UBound(artNew) - 1)
if i > UBound(artNew) then
tempNew = "xxxx" 'Inserts a string to compare to (will show there is a
' difference), and keep from running off the array
else
tempNew = artNew(i)
end if
if i > UBound(artOld) then
tempOld = "xxxx" 'Inserts a string to compare to (will show there is a
' difference), and keep from running off the array
else
tempOld = artOld(i)
end if
i2 = i
if i <= UBound(artOld) and i <= UBound(artNew) then
if i <= UBound(artOld) and i2 <= UBound(artNew) and artNew(i2) <> artOld(i) then
do while i <= UBound(artOld) and i2 <= UBound(artNew) and artNew(i2) <> artOld(i)
i2 = i2 + 1
if i >= UBound(artOld) or i2 >= UBound(artNew) then
exit do
end if
loop
end if
if i <= UBound(artOld) and i2 <= UBound(artNew) and artNew(i2) <> artOld(i) then
do while i < UBound(artOld) and artNew(i2) <> artOld(i)
i2 = i2 - 1
if i <= LBound(artOld) and i2 <= LBound(artNew) then
exit do
end if
loop
end if
if i <= UBound(artOld) and i2 <= UBound(artNew) and artNew(i2) = artOld(i) then
response.Write _
"<span style='color:black; background-color:skyblue'>" & artNew(i2) & "</span>"
elseif artNew(i2) <> artOld(i) then
response.Write _
"<span style='color:black; background-color:gold'>" & artNew(i) & "</span>"
else
response.Write _
"<span style='color:black; background-color:red'>" & artNew(i) & "</span>"
end if
else
i = i
Response.Write _
"<span style='color:black; background-color:cyan'>" & artNew(i) & "</span>"
end if
'Put the periods back in.
Response.Write(".")
Next
%>