VB:帮助修复列表框问题

时间:2014-04-30 08:36:01

标签: vb.net

所以我创建了一个机器人,并且出于某种原因使用代理搜索器,我在ListBox2中的一行显示了所有代理。我需要它每行显示一个代理,任何帮助表示赞赏。谢谢!

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.socialstamp.info/proxies.txt")
    Dim response As System.Net.HttpWebResponse = request.GetResponse()
    Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream)
    Dim scrapeproxy As String = sr.ReadToEnd
    ListBox2.Items.Add(scrapeproxy)
End Sub

出于某种原因,ListBox输出从一行中的http://www.socialstamp.info/proxies.txt中删除的所有代理,而不是每行代理。

1 个答案:

答案 0 :(得分:1)

喜欢的东西;

    Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.socialstamp.info/proxies.txt")
    Dim response As System.Net.HttpWebResponse = request.GetResponse()
    Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream)
    Dim scrapeproxy As String = sr.ReadToEnd

    Dim lstProxyList As New List(Of String)(scrapeproxy.Split(vbLf))

    For Each proxy As String In lstProxyList

        Listbox2.Items.Add(proxy)

    Next

或者如果您有Listbox2.Items.AddRange(不确定您是否正在使用WPF),那么您可以使用它而不是循环。