How do you guys recommend searching an ArrayList for a specific string? My arraylist is defined as:

Public Shared VisioSwitchArray As New ArrayList()

    Public Structure switch
        Public HOSTNAME As String
        Public IP As String
        Public MODEL As String
        Public VLANS As String
        Public NEIs() As neighbor
    End Structure

    Public Structure neighbor
        Public IFACE As String
        Public DIST_IP As String
        Public DIST_IFACE As String
    End Structure

What I'm trying to compare is the IP string from the switch structure and the DIST_IP string from the neighbor structure. Problem is, using VisioSwitchArray.contains(some_ip_address) always returns false. I'm guessing it is searching for a matching switch object with in the list right?

I'm guessing it is searching for a matching switch object with in the list right?

That's right.

You can't use Contains method in this case. You have to loop and cast to find the right value

Dim i As Integer

For i = 0 To VisioSwitchArray.Count - 1
  If CType(VisioSwitchArray.Item(i), switch).IP = "10.0.0.2" Then
    ' Found
    Exit For
  End If
Next i
commented: Solution worked great! Thank you! +2

Sweet! I will give it a try. In the mean time, I used a loop to String.Compare each item. Not what I wanted though. Thanks for the tip!

That worked great. Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.