[RESOLVED] Listbox or checkedlistview search
Greetings
i got a listbox and a textbox, i been trying to get this to search for a word and when it finds the word it returns the whole line. For example if iam searching for "dog" it returns all with "dog" its only returning the exact word. it will not return both with upper and lower case. i been useing this code.
it loads a text file in a listbox first
or how to loop thru a checked listview
Thank you
Dem
Code:
For i As Integer = 0 To (Me.Special_Search_Histroy_CheckedListview.CheckedItems.Count - 1)
Dim path As String = (Me.Special_Search_Histroy_CheckedListview.CheckedItems(i).SubItems(0).Text)
Dim strr As String = (Me.Special_Search_TextBox.Text)
'Dim path As String = (Me.load_special_search_listbox.Items.ToString)
Dim readText() As String = File.ReadAllLines(path)
For Each s As String In readText
If s.Contains(strr ) Then
MsgBox(s)
End If
'End If
Next
Re: Listbox or checkedlistview search
I think Contains is always case sensitive, however you can use IndexOf instead and specify case-insensitivity :
Code:
If s.IndexOf(strr, StringComparison.OrdinalIgnoreCase) <> -1 Then
MessageBox.Show(s)
End If
Or alternatively you can just convert both string to lower or uppercase before comparing (ie use s.ToLower and strr.ToLower)
Re: Listbox or checkedlistview search
Thank you
i was trying the StringComparison.OrdinalIgnoreCase but using it wrong Totaly wrong, Thank you it works perfic :-)
Best regards