Difference between two strings

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Niroj@Work
Pro Scripter
Posts: 63
Joined: Thu Dec 10, 2009 8:13 am

Difference between two strings

Post by Niroj@Work » Sat Dec 26, 2009 5:26 am

Suppose:

Let>str1=12345neil
Let>str2=125neil

How to get the diffrence "34"? Null replacement is not working..

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Jan 01, 2010 6:10 am

Assuming the strings being compared are always the same basic pattern as the example, something like the following will work. Functionally, if you start with two identical strings and make additions to ONE of them. The following will be able to find those additions.

Code: Select all

Let>str1=12345neil
Let>str2=125neil

RegEx>.,Str1,0,var1,var1_count,0
RegEx>.,Str2,0,var2,var2_count,0

Let>kk=0
Let>kkk=0
Let>kkkk=0
Let>diff=

If>var1_count>var2_count
Let>var_count=%var1_count%+1
  Repeat>kk
    Add>kk,1
    Add>kkk,1
    Label>Test1
    If>%kk%<%var_count%
      If>var1_%kk%=Var2_%kkk%
      Else
        Add>kkkk,1
        Let>var_%kkkk%=var1_%kk%
        Add>kk,1
        Goto>Test1
      EndIf
    EndIf
  Until>kk>%var1_count%
Else
  Let>var_count=%var2_count%+1
  Repeat>kkk
    Add>kk,1
    Add>kkk,1
    Label>Test2
    If>%kkk%<%var_count%
      If>var2_%kkk%=Var1_%kk%
      Else
        Add>kkkk,1
        Let>var_%kkkk%=var2_%kkk%
        Add>kkk,1
        Goto>Test2
      EndIf
    EndIf
  Until>kkk>%var2_count%
EndIf

Let>kkkkk=0
Repeat>kkkkk
  Add>kkkkk,1
  Let>value=var_%kkkkk%
  Concat>diff,value
Until>kkkkk,%kkkk%

MDL>diff

Niroj@Work
Pro Scripter
Posts: 63
Joined: Thu Dec 10, 2009 8:13 am

Post by Niroj@Work » Fri Jan 01, 2010 7:38 am

what a :idea: !
Thanks a lot..

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts