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
19/02/1999 16:15:00
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00189473
Message ID:
00189499
Views:
17
>Thanks Mark,
>Actually, I need to check if there are characters outside of a list of valid characters. For example A-Z,a-z,0-9, are valid characters, how can I tell if an address has a value outside of these. I know I'm going to be using ASCII values, but what's the best way to search through the string? I use your method a lot myself when I know what I'm looking for. In this case it could be a rather large set of invalid characters, so I don't think it would be the best choice here. Thanks again.
>Marcus.
>
>>Marcus,
>>If you want to remove the characters (not just locate them) then I recommend STRTRAN:
>>
>>pcName = STRTRAN(pcName, "#", "")
>>pcName = STRTRAN(pcName, "!", "")
>>pcName = STRTRAN(pcName, "$", "")

>>..and so on...
>>
>>This function is nice because it removes every instance very quickly.
>>Mark
>>
>>>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.

A rather brute force approach:

Create a string of all valid characters, and spin through each character of the string, copying it only if it's in the set. Something like:
 FUNCTION StripInvalids
LPARAMETERS cStringToValidate, cListOfValidCharacters
LOCAL cResultString, nLengthOfParmString, nCounter, cThisChar
cResultString = ''
nLengthOfParmString = LEN(cStringToValidate)
FOR nCounter = 1 TO nLengthOfParmString
   cThisChar = SUBST(cStringToValidate, nCounter, 1)
   IF cThisChar $ cListOfValidCharacters
      cResultString = cResultString + cThisChar
   ENDIF
ENDFOR
RETURN cResultString
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform