user4287815
user4287815

Reputation:

How to remove string from list?

I'm creating a program, I have a problem with my list, because in this list, my program stored file, from parsed json, but I don't need all of theese files, so I want to remove its from the list. My code:

For i = 0 To LibrariesList.Count - 1
    '//Lwjgl beta disabled:\\'
    If LibrariesList.Item(i).Contains("org.lwjgl.lwjgl:lwjgl:2.9.1-nightly-20130708-debug3") = True Then
        LibrariesList.Item(i) = LibrariesList.Item(i).Replace("org.lwjgl.lwjgl:lwjgl:2.9.1-nightly-20130708-debug3", Nothing)
    End If
    If LibrariesList.Item(i).Contains("org.lwjgl.lwjgl:lwjgl_util:2.9.1-nightly-20130708-debug3") = True Then
        LibrariesList.Item(i) = LibrariesList.Item(i).Replace("org.lwjgl.lwjgl:lwjgl_util:2.9.1-nightly-20130708-debug3", Nothing)
    End If
    If LibrariesList.Item(i).Contains("org.lwjgl.lwjgl:lwjgl-platform:2.9.1-nightly-20130708-debug3") = True Then
        LibrariesList.Item(i) = LibrariesList.Item(i).Replace("org.lwjgl.lwjgl:lwjgl-platform:2.9.1-nightly-20130708-debug3", Nothing)
    End If
    '//Lwjgl 2.9.2-Beta disabled:\\'
    If LibrariesList.Item(i).Contains("org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-20140822") = True Then
        LibrariesList.Item(i) = LibrariesList.Item(i).Replace("org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-20140822", Nothing)
    End If
    If LibrariesList.Item(i).Contains("org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-20140822") = True Then
        LibrariesList.Item(i) = LibrariesList.Item(i).Replace("org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-20140822", Nothing)
    End If
    If LibrariesList.Item(i).Contains("org.lwjgl.lwjgl:lwjgl-platform:2.9.2-nightly-20140822") = True Then
        LibrariesList.Item(i) = LibrariesList.Item(i).Replace("org.lwjgl.lwjgl:lwjgl-platform:2.9.2-nightly-20140822", Nothing)
    End If
Next

The librarieslist as the list, but my code not remove completely the string, the string index is not removed. I want to remove the string, with the string index so the librarieslist.cont - 1.

How can I do it?

Upvotes: 0

Views: 118

Answers (1)

Idle_Mind
Idle_Mind

Reputation: 39122

Assuming an actual List(Of String) is being used, iterate backwards over the List and use RemoveAt():

    Dim NotAllowed() As String = {
        "org.lwjgl.lwjgl:lwjgl:2.9.1-nightly-20130708-debug3",
        "org.lwjgl.lwjgl:lwjgl_util:2.9.1-nightly-20130708-debug3",
        "org.lwjgl.lwjgl:lwjgl-platform:2.9.1-nightly-20130708-debug3",
        "org.lwjgl.lwjgl:lwjgl:2.9.2-nightly-20140822",
        "org.lwjgl.lwjgl:lwjgl_util:2.9.2-nightly-20140822",
        "org.lwjgl.lwjgl:lwjgl-platform:2.9.2-nightly-20140822"
    }

    For i As Integer = LibrariesList.Count - 1 To 0 Step -1
        For Each entry As String In NotAllowed
            If LibrariesList(i).Contains(entry) Then
                LibrariesList.RemoveAt(i)
                Exit For
            End If
        Next
    Next

Upvotes: 2

Related Questions