Difference between strings

Joshann

Registered User.
Local time
Today, 14:52
Joined
Mar 22, 2002
Messages
142
Is there a way to get the difference between two strings? Not the size difference, but what the characters are that are different.

For example:
If you had
str1 = "See spot run"
str2 = "See the spot run"

Is there some function or something that will return "the" when comparing the two strings? It would be even better if it could return what the characters are that are different as well as tell you the position where they were inserted.
 
Left, Right, repeat? :-P

well... since i am new to VBA-land, i do not know of any VBA methods or functions that do this. however, you could throw the two strings into a long do-while loop comparing each character to the other character. if you process it via a Right() and then process it via a Left() and then compare those differences through the same process. you'll eventually get "the" from your example. there probably is something that does this already.. but it probably does the exact same process. make sense?
 
There is no easy way to do this. There are way to see if one string is within another, like using the Instr() function, so you can do it word-by-word versus character-by-character.
 
Thanks

well... since i am new to VBA-land, i do not know of any VBA methods or functions that do this. however, you could throw the two strings into a long do-while loop comparing each character to the other character. if you process it via a Right() and then process it via a Left() and then compare those differences through the same process. you'll eventually get "the" from your example. there probably is something that does this already.. but it probably does the exact same process. make sense?

There is no easy way to do this. There are way to see if one string is within another, like using the Instr() function, so you can do it word-by-word versus character-by-character.

I figured there wasn't an easy way to do this, but thought I'd ask. Thanks to both of you.
 

Users who are viewing this thread

Back
Top Bottom