Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Finding an exact match in a string
Message
De
28/10/2019 08:43:41
 
 
À
27/10/2019 18:52:53
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01671709
Message ID:
01671719
Vues:
62
>I am trying to find vars and their values in a string, and am having a hassle with similar var names. The vars are not all constantly in the string - in other words, it's a mixture of the vars, and I have to test to see what vars are in the particular string.
>
>If the string has Var1 and Var10 in it, and I test using $, I get a hit on both, but in the example string below, only Var10 is there
>
>VarString= "Var2=cd, Var3=ef, Var4=gh, Var5=ij, Var6=kl, Var7=mn, Var8=op, Var9=qr, Var10=st"
>
>If I use TestVar $ VarString and in that string it has Var10, for example, I will get a hit when testing for TestVar="Var10" as well as when TestVar="Var1".
>
>How do I eliminate this ambiguity?

When you do your comparison, use the == operator to do an exactly equals. And if you need to test for not equals, use "NOT x == y".

>I hope I explained that clearly enough...
>
>Many thanks!

I do something similar in one of my processes.
VarString= "Var2=cd, Var3=ef, Var4=gh, Var5=ij, Var6=kl, Var7=mn, Var8=op, Var9=qr, Var10=st"

DIMENSION laLines[1]
ALINES(laLines, VarString, 2 + 4, ",")
FOR lnI = 1 TO ALEN(laLines, 1)
    * Grab the components
    lcVarName = ALLTRIM(GETWORDNUM(laLines[lnI], 1, "="))
    lcValue   = ALLTRIM(GETWORDNUM(laLines[lnI], 2, "="))

    * Process here
    ? lcVarName, lcValue
NEXT
It will give you the breakout of each item in a comma-separated list like that. And if you have the data in some other way, you can adjust the parse character in ALINES(), or use another method to break out the lines.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform