如何於字串變數中,找到對應的字串位於 矩陣變數中的 Index 值?
可以利用 Array.Indexof() 來搜尋
Array.IndexOf 方法 (Array, Object, Int32)
範例如下:
Dim AttStr() As String = { "aaa", "bbb", "ccc", "abc" }
Dim FindStr As String = ""
Dim FindIndex As Integer
FindStr = "aaa"
FindIndex = Array.IndexOf(AttStr,FindStr)
' Console.WriteLine(FindIndex) 'Print Output: 0
FindStr = "a"
FindIndex = Array.IndexOf(AttStr,FindStr)
' Console.WriteLine(FindIndex) 'Print Output: -1
FindStr = "ccc"
FindIndex = Array.IndexOf(AttStr,FindStr)
' Console.WriteLine(FindIndex) 'Print Output: 2
參考:
MSDN
[入門文章] .NET 陣列詳論