tags:

views:

50

answers:

3

I have two arraylists that contains links in one and the root url in the other. Sometimes the lists dont equal in number and I would like to iterate through the links list and if it contains a matching root url add it to a third list but also avoid any duplicates. I tried this but am not getting consistent results.

Any ideas appreciated, thanks.

For Each link As String In urls
            For Each part As String In post
                If part.Contains(link) Then
                    newPost.Add(part)
                End If
            Next
       Next

Perhaps there is another way; basically the part in post is a link to a page and contains the root url( which is link in urls). After extracting all these I need to ensure the 2 lists match.

A: 

try using nested for loops instead of foreach

transmogrify
A: 

If you are using 2008, then you can use LINQ


For each link as String in urls

    Dim results = (FROM part IN post _
                  SELECT part _
                  WHERE part.Contains(link)). Distinct
Next

You can replace the . Distinct by other functions like First, FirstOrDefault,ToList,ToArray,GroupBy,Sort, and the list goes on.

David Brunelle
Thanks for the reply. I tried it and it did not work. Let me add some more info for clarification.Arraylist post contains the first few items as an example:0 - http://www.blogdetecnologia.com/actualidad/aprobado-oficialmente-cargador-universal-microusb/1- http://www.blogdetecnologia.com2- http://landmine.com.ph/para-las-ventas-del-iphone-apple-original-3gs-32gb-en-200euros/3- http://landmine.com.phand urls contains0 - http://www.blogdetecnologia.com1 - http://landmine.com.phthis is what the problem is; i get new list with the same post items after iterating through it
vbNewbie
A: 

Thanks for the responses, figured it out.

vbNewbie