带字符串的VB.NET数组

时间:2013-05-05 15:31:00

标签: vb.net

如何将数组1中的2到3个元素复制到另一个数组

宠物

狗1 狗2 狗6
猫1 猫2

Dim pet as String = "dog"

我想将数组元素从数组1复制到数组2,只使用名为pet的字符串“dog”LIKE复制

狗1 狗2 狗6

1 个答案:

答案 0 :(得分:4)

这是@ rynah的例子基本上在幕后做的事情:

    Dim array1() As String = {"dog 1", "dog 2", "dog 6", "cat 1", "cat2"}

    Dim tmpList As New List(Of String)
    For Each value As String In array1
        If value.Contains("dog") Then
            tmpList.Add(value)
        End If
    Next

    Dim array2() As String = tmpList.ToArray
    For Each value As String In array2
        Debug.Print(value)
    Next