How do I check to see if a string is within an array in Visual Basic?
Answer:
Dim things As String() = {"a", "b", "c"}
If things.Contains("a") Then
' do things
Else
' don't do things
End If
Use Contains
:
If ShippingMethod.Contains(Shipping) Then
'Go
End If
That implies case-sensitivity. If you want case insensitive:
If ShippingMethod.Contains(Shipping, StringComparer.CurrentCultureIgnoreCase) Then
'Go
End If
I get the error 'Contains' is not a member of 'String()'
if I try the above answer.
Instead I used IndexOf :
Dim index As Integer = Array.IndexOf(ShippingMethod, Shipping)
If index < 0 Then
' not found
End If