我在数组中有大量字符串元素的列表,并且我正在使用contains函数来检查它是否包含该元素。它工作正常。现在我想了解元素的索引/位置。假设数组是
dim s as string() = {"first", "second","third"}
和字符串
dim l as string = "third"
方法
dim b as boolean = s.Contains(l, StringComparer.CurrentCultureIgnoreCase)
旗帜
if (b) Then
messagebox.show("It exists")
end if
上面的数组只是一个例子。原始数组包含7690个条目,每个条目均以utf-8格式编写,并且indexOf函数未给出任何结果
首先,在VB.Net中编写时应考虑使用List(Of T)。
List类提供List(Of T).IndexOf方法(T)。
您可以执行以下操作:
Dim index As Integer = YourList.IndexOf(l)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句