我有一个代理列表,就像IP:PORT,我需要做的是删除端口号为8080,80,431和13的所有代理。我试过用StreamReader来做这个,但没有用,任何帮助家伙?谢谢。
我的代码工作:
Using reader As New StreamReader(o.FileName())
While Not reader.EndOfStream
Dim line As String = reader.ReadLine()
Dim X As String = line.Contains("8080")
For Each X In NsTextBox1.Text
NsTextBox1.Text = NsTextBox1.Text + X
Exit While
Next
End While
End Using
答案 0 :(得分:0)
我最近写了一些可以很好地解决这个问题的方法,如果代理列表每行包含1个IP而不是最后一个空格。
虽然不是最优化的代码,但它运行得很好,这里有一些输出,它解析了大约6000个代理的列表。
你可以这样使用它。
IO.File.WriteAllText("C:\ProxyOut.txt", ParseProxyList(IO.File.ReadAllText("C:\ProxyIn.txt"), 8080, 80, 431, 13))
编辑:哦,我刚看到它是用于文本框,用法不应该是那么不同
TextBoxOut.Text = ParseProxyList(TextBoxIn.Text, 8080, 80, 431, 13))
功能本身:
Private Function ParseProxyList(ByVal list As String, ParamArray ports() As Integer)
Dim splitList() As String = list.Split(vbCrLf)
Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
Dim outputLinesCount As Integer = 0
For Each line As String In splitList
Dim bContainsPort As Boolean = False
For Each port As Integer In ports
If line.EndsWith(":" & port.ToString) Then
bContainsPort = True
End If
Next
If bContainsPort = False Then
sb.AppendLine(line)
outputLinesCount += 1
End If
Next
MsgBox(splitList.Count.ToString & "->" & outputLinesCount.ToString & " (" & (splitList.Count - outputLinesCount) & " Removed)")
Return sb.ToString
End Function