I have a proxy list, that is like IP:PORT, and what I need to do is remove all the proxies with port numbers of 8080, 80, 431, and 13. I've tried to use a StreamReader to do this, but to no avail, any help guys? Thank you.
My code efforts:
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
I recently wrote something that should do the trick nicely, if the proxy list contains 1 IP per line without white space at the end that is.
While not the most optimized code it works pretty well, here's some output of it parsing a list of about 6000 proxies.
You'd use it as such.
IO.File.WriteAllText("C:\ProxyOut.txt", ParseProxyList(IO.File.ReadAllText("C:\ProxyIn.txt"), 8080, 80, 431, 13))
EDIT: oh i just read it was for a textbox, usage should not be that different
TextBoxOut.Text = ParseProxyList(TextBoxIn.Text, 8080, 80, 431, 13))
And the Function itself:
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