Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Opinions for best way to check a string for invalid Char
Message
De
21/02/1999 11:29:56
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00189473
Message ID:
00189794
Vues:
12
Here's one that I would bet is the fastest :)

*-- Build a list of invalid chars
* Obviously, this can be done only once.
gcInvalidChars = ""
for i = 0 to 255
if not between(chr(i), "A", "Z") and ;
not between(chr(i), "a", "z") and ;
not between(chr(i), "0", "9")
gcInvalidChars = gcInvalidChars + chr(i)
endif
endfor

*-- If you want to test if a string contains invalid chars:
if (len(lcString) <> len(chrtran(lcString, gcInvalidChars, "")))
*-- Do whatever
endif

*-- If you want to filter a string:
lcFilteredString = chrtran(lcString, gcInvalidChars, "")

Note: Use chrtran() whenever possible. It's faster than strtran() and, it's MUCH faster than a loop through all the chars in a string.

Vlad

>I need to check names and addresses for invalid characters. What do you guys think is the best command/function to use for this. Thanks for your help.
>Marcus.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform