/ / Ak zoznam obsahuje položku LIKE - vb.net

Ak zoznam obsahuje položku LIKE - vb.net

Je tam kdekoľvek skontrolovať, či zoznam obsahuje položku, ktorá je podobná reťazcu?

Snažil som sa použiť vyhlásenie podobné, ale to nefunguje.

Skúsil som:

For i As Integer = 0 To TopicListBox.Items.Count - 1
If (TopicListBox.Items(i).ToString.Contains(Record.Item("Keyphrase2"))) Then
Dim Item As String = TopicListBox.Items(i).ToString
If Item Like "Questions related to:" & Record.Item("Keyphrase2") & ": |*| Qs" Then
Dim ItemSplit() As String = Item.Split(New Char() {"|"c})
Dim AmountOfQuestionsAfter As Integer = AmountOfQuestions + CInt(ItemSplit(1))
Item = ItemSplit(0) & AmountOfQuestionsAfter & ItemSplit(1)
Else
TopicListBox.Items.Add("Questions related to:" & Record.Item("Keyphrase2") & ": |" & AmountOfQuestions & "| Qs")
Exit For
End If
End If
Next

odpovede:

2 pre odpoveď č. 1

I don "t naozaj pochopiť, čo sa snažíte dosiahnuť, ale tu je funkcia LINQ vrátiť všetky položky, ktoré obsahujú určitý reťazec.

Dim lb As New ListBox

lb.Items.Add("asdf")
lb.Items.Add("asdfasdf")
lb.Items.Add("aifisasdf")
lb.Items.Add("adf")

"" find all items in the ListBox that contain the string "asdf"
Dim found = lb.Items.Cast(Of String).Where(Function(f) f.Contains("asdf"))

For Each s In found
"" do something with those items
Next

0 pre odpoveď č. 2

Nemôžeš to urobiť

If Item.Contains("Questions related to:" & Record.Item("Keyphrase2")) Then
...
End If

alebo

If Item.StartsWith("Questions related to:" & Record.Item("Keyphrase2")) Then
...
End If

?


0 pre odpoveď č. 3
Dim Found = (From Result In lb.Items Where Result.ToString = "Value" Select Result)

If (Found.Count > 0) Then
" your code
End If