I'm a big fan of searching a string with string.contains. I use it heavily. I'm glad it came along to replace instr for searching a string. One thing you might not realize is that you can search your list of custom objects pretty easily. Using my aforementioned generic list of hotels, I can check if that list contains a specific hotel, without having to loop through the list myself to check. The first thing you need to ask yourself, is what you want the search to look for when you're asking if your list contains a hotel. The name of the hotel perhaps? In my case, I decided to use the unique ID of the hotel so I could say:
If hotellist.contains (thishotel) then
Assuming that thishotel contains a property called hotelid, you simply override (and overload apparently) the equals function that is present in every class you create.
Public Class hotel
Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean
If obj Is Nothing OrElse Not Me.GetType() Is obj.GetType() Then
Return False
End If
Dim h As hotel = CType(obj, hotel)
Return Me.hotelid = h.hotelid
End Function
Public hotelid As Integer
Public hotelname As String
End Class
I think that's called the default equalifier or something silly. In any case, its what the contains function uses while searching. Equals is used in a bunch of other built in functions of your list, so be sure to read the remarks section of MSDN for the generic list.