raghx_2000
asked on
Find non-alphabetic char in string in VB
Hi there
I want to verify whether a string has any non alphabetic character or not.
Flow goes like this:
str = "AD1@aYaZ"
If str has Non-Alphabetic character then
Return True
Else str has no Non-Alphabetic Character then
MsgBox "String must have 1 non-alphabetic character"
Retun False
End if
Please help me, with code.
I want to verify whether a string has any non alphabetic character or not.
Flow goes like this:
str = "AD1@aYaZ"
If str has Non-Alphabetic character then
Return True
Else str has no Non-Alphabetic Character then
MsgBox "String must have 1 non-alphabetic character"
Retun False
End if
Please help me, with code.
ASKER
Thanks murray,
I know to do it in .NET way, but unfortunately iam using VB 3. So any user procedure / function etc.
hint: We got LIKE keyword similar to regEx, but i dont know to use it.
any suggestions.....
I know to do it in .NET way, but unfortunately iam using VB 3. So any user procedure / function etc.
hint: We got LIKE keyword similar to regEx, but i dont know to use it.
any suggestions.....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I forgot - if the string can be any length, you have to really check character by character (I haven't checked this, so there may be a typo):
For iX=0 To Str.length
If Str.Char[iX] like "[!A-Za-z]" then
return True
End If
Next
Return False
For iX=0 To Str.length
If Str.Char[iX] like "[!A-Za-z]" then
return True
End If
Next
Return False
Just do:
str = "AD1@aYaZ"
Dim i As Integer, token As Integer
For i = 1 To Len(str)
token = Asc(Mid$(str, i, 1))
If token < 65 Or (token > 90 And token < 97) Or token > 122 Then Return True
Next i
MsgBox "String must have 1 non-alphabetic character"
Return False
str = "AD1@aYaZ"
Dim i As Integer, token As Integer
For i = 1 To Len(str)
token = Asc(Mid$(str, i, 1))
If token < 65 Or (token > 90 And token < 97) Or token > 122 Then Return True
Next i
MsgBox "String must have 1 non-alphabetic character"
Return False
Oh, you have to substitute the stupid return mechanism for "Return." I forgot. So it'd be fooFighterFnc = True: Exit Function, etc.
Dim Str As String = "AD1@aYaZ6"
Dim re As New System.Text.RegularExpress
Dim m As System.Text.RegularExpress
If m.Success Then
MsgBox("String must have 1 non-alphabetic character")
Return False
End If
Return True