[英]Check If a String Contains IPv4 Address in VB.Net
我怎么知道一個字符串是否包含一個IPv4地址。 我想獲取此字符串中的所有IP地址 。
范例:
以下字符串包含4個IPv4地址:
2016-01-16 00:00 - [99.245.14.88] downloaded ...
2016-01-16 00:00 - [120.103.139.95] downloaded ...
2016-01-15 23:59 - [166.118.4.233] downloaded ...
2016-01-15 23:59 - [55.234.129.191] downloaded ...
這是我剛為您提供的每個IP的一些代碼。
Dim Regex As New System.Text.RegularExpressions.Regex("\[(([\d]{1,3}\.?){4})\]", System.Text.RegularExpressions.RegexOptions.Multiline)
Dim matches As System.Text.RegularExpressions.MatchCollection = Regex.Matches(TextBox1.Text) 'Replace textbox with your string source
Dim tmp As String = ""
For Each match As System.Text.RegularExpressions.Match In matches
'Do something with each IP : match.Groups(1).Value
tmp &= match.Groups(1).Value & vbNewLine
Next
MsgBox(tmp)
它使用一個正則表達式。如果您要使用大量文本,則應閱讀有關其工作方式的信息。 如果這是您想要的,請不要忘記將其標記為答案並贊成。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.