Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Opinions for best way to check a string for invalid Char
Message
From
21/02/1999 11:29:56
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00189473
Message ID:
00189794
Views:
11
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.
Previous
Reply
Map
View

Click here to load this message in the networking platform