cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
MathStatChem
Level VI

Compare strings and highlight differences

How would I write a function or routine that would compare two strings and show the difference between them?

e.g.

string1="It will rain tomorrow"

string2="It will snow tomorrow"

comparison result (string2 vs string 1) = "It will rainsnow tomorrow"

6 REPLIES 6
txnelson
Super User

Re: Compare strings and highlight differences

What are the rules?
Is
It will rain tomorrow
different from
Tomorrow it will rain
If you are just comparing each word from one string to the same position word in a second string, that can easily be done by looping through the strings using the Word() function to compare each word.
But going beyond that, the algorithm can become very complex
Jim
MathStatChem
Level VI

Re: Compare strings and highlight differences

What I want is something akin to what MS Word will do when it compares documents.  

The actual thing I want to do is when comparing two data tables, particularly differences in tables scripts and column formulas. 

 

Compare Data Tables will show, for instance, if saved table scripts are different and list them both out, which I can save to a table with the strings in the table in separated columns, but what I want to see is where those two scripts are different.  

MathStatChem
Level VI

Re: Compare strings and highlight differences

Seems like this could be done with regular expressions, I just don't know how.  

Craige_Hales
Super User

Re: Compare strings and highlight differences

MathStatChem
Level VI

Re: Compare strings and highlight differences

Shortest Edit Script gets me the information that I need, that is very helpful, thanks!