使用VB.net提取Url的一部分
我有这个网址 我试图从URL中提取31.888433,73.263572 并将31.888433发送到文本框1 和73.263572至文本框2 你能给我举个例子吗?我如何使用正则表达式或其他任何东西来实现这一点?你可以使用string.split()。此方法采用一个字符数组,这些字符是用于拆分的判别符。更好的解决方案是按“/”拆分,取以“@”开头的字符串,然后按“,”拆分。您将有一个包含两个字符串的数组:第一个纬度,第二个经度。使用VB.net提取Url的一部分,vb.net,google-maps,Vb.net,Google Maps,我有这个网址 我试图从URL中提取31.888433,73.263572 并将31.888433发送到文本框1 和73.263572至文本框2 你能给我举个例子吗?我如何使用正则表达式或其他任何东西来实现这一点?你可以使用string.split()。此方法采用一个字符数组,这些字符是用于拆分的判别符。更好的解决方案是按“/”拆分,取以“@”开头的字符串,然后按“,”拆分。您将有一个包含两个字符串的数组:第一个纬度,第二个经度。 应立即使用LINQ解释见代码注释 Dim strURL
应立即使用LINQ解释见代码注释
Dim strURL As String = "https://www.google.com/maps/place/Aleem+Iqbal+SEO/@31.888433,73.263572,17z/data=!3m1!4b1!4m5!3m4!1s0x39221cb7e4154211:0x9cf2bb941cace556!8m2!3d31.888433!4d73.2657607"
'Find the index of the first occurance of the @ character
Dim index As Integer = strURL.IndexOf("@")
'Get the string from that the next character to the end of the string
Dim firstSubstring As String = strURL.Substring(index + 1)
'Get a Char array of the separators
Dim separators As Char() = {CChar(",")}
'Split the string into an array based on the separator; the separator is not part of the array
Dim strArray As String() = firstSubstring.Split(separators)
'The first and second elements of the array is what you want
Dim strTextBox1 As String = strArray(0)
Dim strTextBox2 As String = strArray(1)
Debug.Print($"{strTextBox1} For TextBox1 and {strTextBox2} for TextBox2")
最后我自己做了一个工作代码 Private _regas Regex=新 Regex(@(-[\d].[\d]),(-[\d].[\d]),RegexOptions.IgnoreCase) 私有子FlatButton1\u单击(发送者作为对象,e作为事件参数)处理FlatButton1。单击 Dim url As String=WebBrowser2.url.AbsoluteUri.ToString()
你能举个例子吗
' The input string.
Dim value As String = WebBrowser2.Url.ToString
Dim myString As String = WebBrowser2.Url.ToString
Dim regex1 = New Regex("@(-?\d+\.\d+)")
Dim regex2 = New Regex(",(-?\d+\.\d+)")
Dim match = regex1.Match(myString)
Dim match2 = regex2.Match(myString)
If match.Success Then
Dim match3 As String = match.Value.Replace("@", "")
Dim match4 As String = match2.Value.Replace(",", "")
Label1.Text = match3
Label2.Text = match4
End If
End Sub
Dim url As String = "www.google.com/maps/place/Aleem+Iqbal+SEO/@31.888433,73.263572,17z/data=!3m1!4b1!4m5!3m4!1s0x39221cb7e4154211:0x9cf2bb941cace556!8m2!3d31.888433!4d73.2657607"
Dim temp As String = Regex.Match(url, "@.*,").Value.Replace("@", "")
Dim arrTemp As String() = temp.Split(New String() {","}, StringSplitOptions.None)
Label1.Text = arrTemp(0)
Label2.Text = arrTemp(1)