Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
String differences
Message
From
21/05/2010 09:35:46
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01465324
Message ID:
01465410
Views:
86
>Is there a function that indicates which chars differ between 2 strings?
s1='abcde'

s2='abCde1'


? "native version",StringDifference(m.s1,m.s2)

? "text version",CAST(CHRTRAN(StringDifference(m.s1,m.s2),0h00FF,'=#') AS M)

? "match chars on first string",StringGetMatch(m.s1,m.s2)

* simple to do other functions

FUNCTION StringDifference(s1,s2)
* return a binary pattern: 00 match, FF unmatch
LOCAL sDiffMask
sDiffMask = BITXOR(CAST(m.s1 AS W),CAST(m.s2 AS W))
RETURN BITOR(BITNOT(CHRTRAN(m.sDiffMask ,0h0,0hFF)),m.sDiffMask)

FUNCTION StringGetMatch(s1,s2)
RETURN CAST(CHRTRAN(BITAND(BITNOT(StringDifference(@m.s1,@m.s2)),CAST(m.s1 AS W)),0H0," ") AS M)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform