Click to See Complete Forum and Search --> : how to search a string character by character


olemiss
November 28th, 1999, 11:53 AM
Hi everyone,

Need to be able to search a string and compare each character to a list of valid characters.

example:
string1="vb-programming"
string2="vb=programming"
valid characters are a-z, A-Z, 0-9, _, -, .

this would find all these characters valid in string1 to be valid and find "=" in string2 to be invalid thus making that string an invalid string

any help or direction would be appreciated

btw i have been trying to use instr functions to accomplish this and have only been able to search
for "1" character at a time :(

thx harold

olemiss
November 28th, 1999, 11:54 AM
sorry but the category should not be activex, should be controls or misc

czimmerman
December 1st, 1999, 05:24 PM
public Function ValidString(byval sInput as string) as Boolean

Dim iLen as Integer
Dim iCtr as Integer
Dim sChar as string

iLen = len(sInput)
for iCtr = 1 to iLen
sChar = mid(sInput, iCtr, 1)
If Not sChar Like "[0-9A-Za-z_]" And sChar <> "-" then Exit Function
next
ValidString = true

End Function