Vb.net – How to check to see if a string is within an array in Visual Basic


I am a PHP developer and not a Visual Basic person.

I have an array:

Dim ShippingMethod() As String = {"Standard Shipping", "Ground EST"}
Dim Shipping as String = "Ground EST"

How do I do an if statement that will check if the string Shipping is in the ShippingMethod() array?

Best Solution

Use Contains:

If ShippingMethod.Contains(Shipping) Then
End If

That implies case-sensitivity. If you want case insensitive:

If ShippingMethod.Contains(Shipping, StringComparer.CurrentCultureIgnoreCase) Then
End If
Related Question