开发者

vb.net, iterating through arraylists

开发者 https://www.devze.com 2022-12-15 07:53 出处:网络
I have two arraylists that contains links in one an开发者_StackOverflow社区d the root url in the other. Sometimes the lists dont equal in number and I would like to iterate through the links list and

I have two arraylists that contains links in one an开发者_StackOverflow社区d 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消