Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to find a specific character
Message
 
 
À
24/02/2000 15:34:57
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00337052
Message ID:
00337082
Vues:
12
>I'm looking for the best way to find a specific characters in a string.
>
>Assuming I have a memo field. I search for a specific character. Lets say it's on position 143. Now, that I have found that position, I need to find the last occurence of a specific character before that position.
>
>So, if I have the following string:
>
>The Montreal Canadians will try to win their 7 games in a row.
>
>Lets say I was looking for the string "mes". The position would then be 50. I then need to find the last occurence of a specific character before position 50. I am looking for a space. So, the position I am looking for is 47.
>
>I wouldn't want to use a DO WHILE approach and skipping a minus one character at a time until I find the space. I am looking for something more direct.

Michel,
I think code below does what you want:
lcStr = "The Montreal Canadians will try to win their 7 games in a row"
lcSearch1 = "mes"
lcSearch2 = Space(1)
lnPos1 = ATC(lcSearch1, lcStr)
IF lnPos1 > 0
    lnPos2 = RATC(lcSearch2, Left(lcStr, lnPos1-1))
ELSE
    lnPos2 = 0
ENDIF
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform