我是PHP开发人员,而不是Visual Basic人员。
我有一个数组:
Dim ShippingMethod() As String = {"Standard Shipping", "Ground EST"}
Dim Shipping as String = "Ground EST"
如何使用if
语句检查字符串Shipping
是否在ShippingMethod()
数组中?
答案 0 :(得分:36)
使用Contains
:
If ShippingMethod.Contains(Shipping) Then
'Go
End If
这意味着区分大小写。如果你想要不区分大小写:
If ShippingMethod.Contains(Shipping, StringComparer.CurrentCultureIgnoreCase) Then
'Go
End If
答案 1 :(得分:1)
如果尝试上述答案,我会收到错误'Contains' is not a member of 'String()'
。
相反,我使用了IndexOf:
Dim index As Integer = Array.IndexOf(ShippingMethod, Shipping)
if index < 0 then
' not found
endif
答案 2 :(得分:0)
答案:
Dim things As String() = {"a", "b", "c"}
If things.Contains("a") Then
' do things
Else
' don't do things
End If