Search code examples
vb.netif-statementlistboxcomparecontains

VB.NET if-statement with 2 ListBoxes


Let's keep it short :)

listbox1 has a list of words.

listbox2 has some random sentences.

I want to check if the current item in listbox2 contains any of the words listed in listbox1. How to accomplish that?

What I got so far is a loop for listbox2, but I don't know how to compare with the other listbox.

For l_index As Integer = 0 To lst1.Items.Count - 1
    Dim l_text As String = CStr(lst1.Items(l_index))
    '???????
Next

Solution

  •     For Each s As String In ListBox1.Items
            If ListBox2.SelectedItem.ToString.Contains(s) Then
                'it contains the word
            End If
        Next