Question Finding similar instead of equal to

daves2369

Member
Joined
Apr 2, 2012
Messages
5
Programming Experience
1-3
Hi Guys

Here is the scenario I want to be able to filter similar words from a search in a text box to items which are in a array then this populates the filter into a list box

For example if the text box contains Tes it would bring up a record like Test + I don't want it to be caps sensitive

Here is what I have so far

VB.NET:
If searchbar.Text = item.name(counter) Then                frmFilteredList.ListView1.Items.Add(item.ID(counter))
                frmFilteredList.ListView1.Items(frmFilteredList.ListView1.Items.Count - 1).SubItems.Add(item.name(counter))
                frmFilteredList.ListView1.Items(frmFilteredList.ListView1.Items.Count - 1).SubItems.Add(item.code(counter))
                frmFilteredList.ListView1.Items(frmFilteredList.ListView1.Items.Count - 1).SubItems.Add(item.totalquantity(counter))
                frmFilteredList.ListView1.Items(frmFilteredList.ListView1.Items.Count - 1).SubItems.Add(item.price(counter))


            End If

Which populates it will equal to data but I want similar

Anyone have any ideas

Cheers

Dave
 
Like Operator (Visual Basic) can be used, it is case insensitive with Option Compare Text, or you can for example do String.ToLower both.
Alternative can be to use String.Contains method, also in combination with ToLower to eliminate case differences.
Here's the reference for String Class (System)
 
Thanks for the reply, that function seems quite handy which ill probably use for future use but I managed to find a solution which I think would be a bit quicker when comparing large amounts of records

Decided to filter my database instead and do it like that
VB.NET:
        objDataView.RowFilter = "ItemName LIKE '" & searchbar.Text & "*'"


        Dim i As Integer = 0
        For i = 0 To objCurrencyManager.Count - 1
            FilteredList.ListView1.Items.Add(CType(objDataView(i)("ID"), String))
            FilteredList.ListView1.Items(FilteredList.ListView1.Items.Count - 1).SubItems.Add(CType(objDataView(i)("ItemName"), String))
            FilteredList.ListView1.Items(FilteredList.ListView1.Items.Count - 1).SubItems.Add(CType(objDataView(i)("ItemCode"), String))
            FilteredList.ListView1.Items(FilteredList.ListView1.Items.Count - 1).SubItems.Add(CType(objDataView(i)("ItemPrice"), String))
            FilteredList.ListView1.Items(FilteredList.ListView1.Items.Count - 1).SubItems.Add(CType(objDataView(i)("ItemQuantity"), String))


        Next
        FilteredList.Show()
 
Back
Top