Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共3 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:无法正常解析公网IP地址时报错处理

1楼
L88919138 发表于:2024/11/19 10:25:00
下面代码能正常解析出公网IP地址时是不会报错,可一旦无法有效解析出公网IP地址时便会报错,测得是最后一行代码报错,该如何用判断语句来规避?


Dim hc As New HttpClient("https://ip.51240.com/") '无法有效解析出公网IP地址
'Dim hc As New HttpClient("http://myip.ipip.net")  '可以正常解析出公网IP地址
Dim txt As String = hc.GetData()
Dim pattern As String = "((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?) "
Dim rgx = New System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim Matches As Object = rgx.Matches(txt)

output.show(Matches.Item(0).Value)  '测得报错的代码


图片点击可在新窗口打开查看
2楼
有点蓝 发表于:2024/11/19 10:40:00
Dim rgx = New System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
Dim Matches As System.Text.RegularExpressions.MatchCollection = rgx.Matches(txt)
If Matches.Count > 0 Then
    output.show(Matches.Item(0).Value)  '测得报错的代码
End If 

3楼
L88919138 发表于:2024/11/19 10:41:00
谢谢大师指点图片点击可在新窗口打开查看
共3 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .02734 s, 2 queries.