2013-12-18 33 views
1

我有這個充滿數據的Dim transactionArray As String()(),兩個或多個元素具有相同的值。vb.net得到數組當前位置的索引

當我想通過數組搜索找到的東西,我有:

For Each tempString As String In transactionArray(tempInt1) 
    If tempString.Contains(searchText) Then 
     MessageBox.Show("Found It") 
    End If 
    Next 

現在我將如何獲得當前的指數?因爲我有相同值的多個elemets,我猜,我不能使用Array.IndexOf

回答

1

切換到一個for循環嘗試:

For I = 0 To transactionArray(tempInt1).Count - 1 
    If transactionArray(tempInt1)(I).Contains(searchText) Then 
     MessageBox.Show("Found It at index " & I.ToString()) 
    End If 
    Next 
1

這個根據你

Dim strArray As String() = {"ABC", "BCD", "CDE", "DEF", "EFG", "FGH", _ 
    "GHI"} 
Array.IndexOf(strArray, "C") 
' not found, returns -1 
Array.IndexOf(strArray, "CDE") 
' found, returns index