如何在vb.net中显示数组列表的内容

时间:2019-09-04 07:35:47

标签: vb.net

我想与字符串一起显示索引。这就是我尝试过的。

 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

现在,我陷入困境,因为我不知道如何将索引和内容一起显示。感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

当您需要使用相应的索引循环数组时,请使用For...Next Statement (Visual Basic)

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

答案 1 :(得分:1)

        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