如何检查字符串是否在 Visual Basic 中的数组中? [英] How do I check to see if a string is within an array in Visual Basic?
本文介绍了如何检查字符串是否在 Visual Basic 中的数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一名 PHP 开发人员,而不是 Visual Basic 人员.
I am a PHP developer and not a Visual Basic person.
我有一个数组:
Dim ShippingMethod() As String = {"Standard Shipping", "Ground EST"}
Dim Shipping as String = "Ground EST"
如何执行 if
语句来检查字符串 Shipping
是否在 ShippingMethod()
数组中?
How do I do an if
statement that will check if the string Shipping
is in the ShippingMethod()
array?
推荐答案
使用 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
这篇关于如何检查字符串是否在 Visual Basic 中的数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文