Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
String differences
Message
De
21/05/2010 09:35:46
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01465324
Message ID:
01465410
Vues:
87
>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)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform