Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-05-2002, 01:28 PM   PM User | #1
maryhill
New to the CF scene

 
Join Date: Aug 2002
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
maryhill is an unknown quantity at this point
Showing the difference between two strings

I have two variables each holding a string of data. The string may be a simple short sentence of text, it may be several paragraphs of text.

Call one "Original", and the other "Modified"
The "Modified" string is a modified version of the the "Original".

On my ASP page I need to show both strings side by side, that's no problem! However to aid my users in finding the modifications I want to highlight using a background color or font color where the modified string differs from the original.

I was just wondering if anyone had tackled anything like this before?

I would really appreciate any help you could give me.

Mary Hill.
maryhill is offline   Reply With Quote
Old 08-06-2002, 08:28 AM   PM User | #2
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
Whell, In VB you have a stringfunction that's Mid(string,geginning,number) and it does the following

example : Mid(abcdef,4,2) returns the string "de"

if you would make something like

dim string1, string2

string1=request.form("string1")
string2=request.form("string2")

if Mid(string1,1,1) <> Mid(string2,1,1) then
response.write("<font color='red'> & Mid(string1,1,1) & "</font>")
else
response.write(Mid(string1,1,1))
end if


you would see if the first caracter of the two strings is equal (black font) or not (red font).

You could do this for every possition in the strings. I cant immediatly come up with some kind of loop-function to do it in an ellegant way, buth perhaps someone else can.

(One way is to break up the string on your form and place every caracter in one textfield and then use a
for each input in request.form
(above code)
next
loop. buth it's not user-friendly)
raf is offline   Reply With Quote
Old 08-07-2002, 11:51 PM   PM User | #3
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
Hmm... just brainstorming here... but why not split up both strings by the SPACE character (" ") into two arrays, and then just try to match the words?

Once a word doesn't match, perhaps run a second nested loop that highlights the words until they match the current word, and then break out of the nested loop and continue matching the arrays?
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Old 08-08-2002, 08:46 AM   PM User | #4
raf
Master Coder


 
Join Date: Jul 2002
Posts: 6,589
Thanks: 0
Thanked 0 Times in 0 Posts
raf will become famous soon enoughraf will become famous soon enough
Nice thinking. Buth what happens if a user just inserts one space to many in one of the strings ?
If you get an empty cell in your array, all the following words won't match, and it might not be very clear for the user what the difference was.
I don't think their is an easy sollution here. You'll probaby have to run more then one routine here. (perhaps depending on the length of the string)

something like

if Len(string1) < 20 then
routine1
else
if Len(string1) < 50 then
routine2
...

Last edited by raf; 08-08-2002 at 08:48 AM..
raf is offline   Reply With Quote
Old 08-09-2002, 12:18 AM   PM User | #5
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
I think i got it sorta going where whammy suggested but there is some recursive error.

Code:
<%
Dim String1, String2
String1 = Request.Form("String1")
String2 = Request.Form("String2")

If String1 <> "" And String2 <> "" Then
Dim Words1(800)
Dim Words2(800)
Dim x, y, temp
x = 1
y = 1
    
    'Seperate the first sentence into a string
    Do
    temp = InStr(x, String1, " ", vbTextCompare)
    If temp = 0 Then Exit Do
    Words1(y) = Mid(String1, x, temp - 1)
    x = temp + 1
    y = y + 1
    Loop Until x = Len(String1)
    
    temp = ""
    For z = 1 To y
    temp = temp & Words1(z) & vbCrLf
    Next z
    
    
End If
%>
<p><FORM action="" Method="POST">
<INPUT type="text" name="String1">
<BR><BR>
<INPUT type="text" name="String2">
<BR>
<INPUT type="Submit" value="Compare">
</FORM>
</p>
<p>
<%=temp%>
</p>
Perhaps someone can see whats wrong with it. Try the code out and you'll see the problem.
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 08-12-2002, 06:44 PM   PM User | #6
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
Mary Hill


Are both the original and modified strings going to be pre written with no user inter-action?
Mr J is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:13 AM.


Advertisement
Log in to turn off these ads.