我可以在数组中查看字符串来自哪个部分吗?

时间:2013-04-04 21:27:42

标签: .net arrays vb.net

如果我有像

这样的数组
Dim list As String()

并使用

从文件中读取列表
list = Split("filehere.txt", ",")

我使用类似

的东西
If list.Contains("string") then
code here
End If

我可以找出数组“string”来自哪个字符串,例如:string(0)或string(16)

1 个答案:

答案 0 :(得分:5)

在.NET中,要查找列表中对象的位置,可以使用IndexOf

如果找不到对象,该方法将返回-1。这允许您使用相同的metod来检查列表是否包含对象及其位置。