我最近写了一些应该可以很好地解决问题的东西,如果代理列表每行包含 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