SETP
asked on
Checking if a variable is in a list of values
Is there a quicker way to check if a String variable in VB 2005 is in a list of values? For example, instead of the following:
Dim x As String
If x = "Mr" Or x = "Mrs" Or x = "Miss" Or x = "Ms" Or x = "Prof" Or x = "Doc" Then
'Do something
End If
Isn't there something like this?:
Dim x As String
Dim values() As String = {"Mr", "Mrs", "Miss", "Ms", "Prof", "Doc"}
If x IsIn values Then
'Do something
End If
Something along those lines?
Thanks
Dim x As String
If x = "Mr" Or x = "Mrs" Or x = "Miss" Or x = "Ms" Or x = "Prof" Or x = "Doc" Then
'Do something
End If
Isn't there something like this?:
Dim x As String
Dim values() As String = {"Mr", "Mrs", "Miss", "Ms", "Prof", "Doc"}
If x IsIn values Then
'Do something
End If
Something along those lines?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you break on fieldValues you can see the filed break down of this item.
from there you can look for different string item that you want.
Sample:
Dim strTest As String = "Dr. Jane O Smith M.D."
Dim fieldValues As String() = ParseLine(strTest)
End Sub
Private Shared Function ParseLine(ByVal oneLine As String) As String()
Dim pattern As String = "[ ,]+(?=(?:[^""]*""[^""]*"")
Dim r As System.Text.RegularExpress
New System.Text.RegularExpress
Return r.Split(oneLine)
End Function