skip to Main Content

I have this URL

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

I am trying to Extract 31.888433,73.263572 from the URL
and send 31.888433 to TextBox 1
and 73.263572 to TextBox 2

Can you give me an example how can i do this with regex or anything else

4

Answers


  1. Chosen as BEST ANSWER

    Finally Made a working Code Myself

    Private _reg As Regex = New Regex("@(-?[d].[d]),(-?[d].[d])", RegexOptions.IgnoreCase) Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click 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
    

  2. You can use string.split(). This method takes an array of chars which are the discriminants for the splitting. The better solution is to split by ‘/’, take the string that starts with ‘@’ and then split it by ‘,’. You’ll have an array with two string: first latitude, second longitude.
    Should be immediate using LINQ

    Login or Signup to reply.
  3. The explanation is in the code comments.

        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")
    
    Login or Signup to reply.
  4.         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)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search