我是PHP开发人员而不是Visual Basic人员.
我有一个数组:
Dim ShippingMethod() As String = {"Standard Shipping", "Ground EST"}
Dim Shipping as String = "Ground EST"
Run Code Online (Sandbox Code Playgroud)
如何执行一个if语句来检查字符串Shipping是否在ShippingMethod()数组中?
vcs*_*nes 38
用途Contains:
If ShippingMethod.Contains(Shipping) Then
'Go
End If
Run Code Online (Sandbox Code Playgroud)
这意味着区分大小写.如果您想要不区分大小写:
If ShippingMethod.Contains(Shipping, StringComparer.CurrentCultureIgnoreCase) Then
'Go
End If
Run Code Online (Sandbox Code Playgroud)
'Contains' is not a member of 'String()'如果我尝试上述答案,我会收到错误消息。
相反,我使用了IndexOf:
Dim index As Integer = Array.IndexOf(ShippingMethod, Shipping)
If index < 0 Then
' not found
End If
Run Code Online (Sandbox Code Playgroud)