我正在尝试制作一个 Skype 解析器,我已经有一个 API,现在我的所有代码都在工作,但不仅仅是显示他们的 IP,而是在它前面显示一些 html 代码,例如:<h1><b>0.0.0.0</b></h1>
,我将如何从文本框中删除随机文本,这个解析器也是在 Visual Basic 中制作的!以下是我用来解决的代码,如果有帮助的话:
Try
DownloadResponse = GetResponse.DownloadString("http://SKYPEAPIHERE.com/&name=" & TextBox7.Text)
FormatResponse = DownloadResponse.Split(New Char() {ControlChars.Lf}, StringSplitOptions.RemoveEmptyEntries)
TextBox8.Text = FormatResponse(0)
Dim sText() As String
sText = Split(TextBox8.Text, ":")
If sText(0) = "168.63.55.14" Then
TextBox8.Text = "IP Not Found"
ListBox1.Items.Add("SKYPE RESOLVER: IP Not Found")
Else
TextBox8.Text = sText(-2)
ListBox1.Items.Add("SKYPE RESOLVER: Resolved " + TextBox7.Text + " - " + TextBox8.Text)
End If
Catch ex As Exception
End Try
如果有人能帮助我解决这个问题,将不胜感激!
使用正则表达式来匹配 IPv4 格式怎么样?
Imports System.Text.RegularExpressions
Dim regex As Regex = New Regex("^([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3}).([0-9]{1,3})$")
Dim match As Match = regex.Match("<h1><b>0.0.0.0</b></h1>")
If match.Success Then
sText=match.Value
End If
以上未经测试,但希望为您指明正确的方向。
http://answers.oreilly.com/topic/318-how-to-match-ipv4-addresses-with-regular-expressions/