lara
lara

Reputation: 83

How to display the content of array list in vb.net

I would like to display index together with the string. This is what I have tried.

 Dim strA As String = "Bell-in-hospital"
 Dim i As Integer = 1

 Dim arrayList() As String = strA.Split({" - "}, StringSplitOptions.RemoveEmptyEntries)

For index As Integer = 0 To arrayList.Length - 1
    MsgBox("location:" & arrayList(index) & arrayList.ToString())
    index += 1
Next

Now, I'm stuck at For each on how can I display the index together with content. Thanks for the help.

Upvotes: 0

Views: 2987

Answers (2)

Fabio
Fabio

Reputation: 32455

When you need to loop array with corresponding index use For...Next Statement (Visual Basic)

For index As Integer = 0 To arrayList.Length - 1
    MsgBox($"index: {index}, value: {arrayList(index)}")
Next

Upvotes: 3

Eugene Ogongo
Eugene Ogongo

Reputation: 375

        Dim strA As String = "Bell-in-hospital"
        'index starts from 0 in arrays
        Dim i As Integer = 0

        Dim arrayList() As String = strA.Split({"-"}, StringSplitOptions.RemoveEmptyEntries)
        For Each test As String In arrayList
        MsgBox("Index: "& i &" String:  "& test)
        'increase index
        i = i + 1
        Next

Upvotes: 1

Related Questions