本文介绍了Vb Net检查arrayList是否包含子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用myArrayList.Contains(myString)
和myArrayList.IndexOf(myString)
来检查arrayList是否包含提供的字符串并分别获取其索引.
I am using myArrayList.Contains(myString)
and myArrayList.IndexOf(myString)
to check if arrayList contains provided string and get its index respectively.
但是,如何检查是否包含子字符串?
But, How could I check if contains a substring?
Dim myArrayList as New ArrayList()
myArrayList.add("sub1;sub2")
myArrayList.add("sub3;sub4")
所以,类似myArrayList.Contains("sub3")
应该返回True
so, something like, myArrayList.Contains("sub3")
should return True
推荐答案
那么您可以使用ArrayList来搜索子字符串
Well you could use the ArrayList to search for substrings with
Dim result = myArrayList.ToArray().Any(Function(x) x.ToString().Contains("sub3"))
当然,使用强类型的List(Of String)的建议是绝对正确的.
Of course the advice to use a strongly typed List(Of String) is absolutely correct.
这篇关于Vb Net检查arrayList是否包含子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!