1

我有以下代码:

  'get the items from listbox4
       For Each aa As String In ListBox4.Items
        'convert string to uri and grap the hostname for each item in listbox4
        Dim myuri As New Uri(aa)
        Dim baseUri As String = myuri.GetLeftPart(UriPartial.Authority)
        ' check if the hostname exist on items of listbox2 and skip the duplicate
            If ListBox2.Items.Contains(baseUri) Then
                Return
            Else
                ListBox2.Items.Add(aa)
            End If
        Next

如何根据第一个 ListBox 中的数据使第二个 ListBox 包含不同的值?

4

2 回答 2

0

这是一个 Linq 基本方法(视为伪代码,我没有时间在可行的解决方案上对其进行测试):

ListBox2.Items.AddRange( _
    ListBox4.Items.Select( _
        Function(x) new Uri(x).GetLeftPart(UriPartial.Authority)).Distinct() _
) ' End AddRange

基本上,它会添加从 ListBox4 中选择的一系列项目,其中使用每个元素选择一个新的 Uri,然后使用您的方法修改 Uri,然后选择修改后的 uri 的不同字符串表示形式。

于 2013-04-09T15:35:20.560 回答
0

在开始循环之前清除 listbox2。在循环内,将“返回”更改为“继续”

于 2013-04-10T20:50:17.307 回答