Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Complicated string formatting. HELP!!!

Complicated string formatting. HELP!!!

Scheduled Pinned Locked Moved Visual Basic
helptutorialcsharpcss
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Floodlight
    wrote on last edited by
    #1

    Hi all, I have an issue that has nearly been causing my poor VB.net non-savvy brain to melt. I need to be able to copy a certain url into a textbox, and then be able to extract certain parts of that URL and then place them in a data grid. Thankfully most of the parts I need in the URL are seperated by ampersands (&) which should make detecting them easier..? The Url might look something like below: adredirect?readform&admodel=mazda3&unid=ff501d42303c0601ca2574790021874b&make=generalnews&model=safety&time=0&client=1&adtype=useful&page=news&site=va I need to be able, for example, to extract the following values out of the above URL: admodel=mazda3 make=generalnews model=safety page=news and somehow convert those above values into: mazda3 generalnews safety news THEN I have to place those values into a data grid... lol I have a certain idea how to do it, but I have no idea how to VB it. Any insight or help would be appreciated. And forgive me if my explanation is lacking. Thanks in advance!

    W 1 Reply Last reply
    0
    • F Floodlight

      Hi all, I have an issue that has nearly been causing my poor VB.net non-savvy brain to melt. I need to be able to copy a certain url into a textbox, and then be able to extract certain parts of that URL and then place them in a data grid. Thankfully most of the parts I need in the URL are seperated by ampersands (&) which should make detecting them easier..? The Url might look something like below: adredirect?readform&admodel=mazda3&unid=ff501d42303c0601ca2574790021874b&make=generalnews&model=safety&time=0&client=1&adtype=useful&page=news&site=va I need to be able, for example, to extract the following values out of the above URL: admodel=mazda3 make=generalnews model=safety page=news and somehow convert those above values into: mazda3 generalnews safety news THEN I have to place those values into a data grid... lol I have a certain idea how to do it, but I have no idea how to VB it. Any insight or help would be appreciated. And forgive me if my explanation is lacking. Thanks in advance!

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #2

      Hi FloodLight I take it that the keywords (admodel,make,model,page) remain constant and only the values change, then you could use a function like this :

      Private Function ExtractValue(ByVal URL As String, ByVal Category As String) As String

          Dim strValue As String = String.Empty
          Dim strSplitURL() As String = Split(strUrl, "&" & Category & "=")
          Dim strSecondSplit() As String = Split(strSplitURL(1), "&")
          strValue = strSecondSplit(0)
          Return strValue
      
      End Function
      

      then you could just call it like this ExtractValue(strUrl, "admodel") Hope this helps.

      F 1 Reply Last reply
      0
      • W Wayne Gaylard

        Hi FloodLight I take it that the keywords (admodel,make,model,page) remain constant and only the values change, then you could use a function like this :

        Private Function ExtractValue(ByVal URL As String, ByVal Category As String) As String

            Dim strValue As String = String.Empty
            Dim strSplitURL() As String = Split(strUrl, "&" & Category & "=")
            Dim strSecondSplit() As String = Split(strSplitURL(1), "&")
            strValue = strSecondSplit(0)
            Return strValue
        
        End Function
        

        then you could just call it like this ExtractValue(strUrl, "admodel") Hope this helps.

        F Offline
        F Offline
        Floodlight
        wrote on last edited by
        #3

        zimvbcoder you are an absolute legend! I actually got it to work, thanks so much for your help :)

        W 1 Reply Last reply
        0
        • F Floodlight

          zimvbcoder you are an absolute legend! I actually got it to work, thanks so much for your help :)

          W Offline
          W Offline
          Wayne Gaylard
          wrote on last edited by
          #4

          No Worries. Thats what I'm here for.

          F 1 Reply Last reply
          0
          • W Wayne Gaylard

            No Worries. Thats what I'm here for.

            F Offline
            F Offline
            Floodlight
            wrote on last edited by
            #5

            Thanks again to Zimvbcoder for his awesome code which worked perfectly for me. Hi again, stuck with another dilemma :( Out of the above HTML I need to extract the values inbetween the > and the <. So in this case, I would need to extract: 9, 1.59 KB, 9, 9 The HTML string could be any length... it will never be a fixed length Again, any assistance will be hugeley appreciated! :)

            W 1 Reply Last reply
            0
            • F Floodlight

              Thanks again to Zimvbcoder for his awesome code which worked perfectly for me. Hi again, stuck with another dilemma :( Out of the above HTML I need to extract the values inbetween the > and the <. So in this case, I would need to extract: 9, 1.59 KB, 9, 9 The HTML string could be any length... it will never be a fixed length Again, any assistance will be hugeley appreciated! :)

              W Offline
              W Offline
              Wayne Gaylard
              wrote on last edited by
              #6

              Hi floodlight. The answer to this really depends on the HTML to parse. For a parser to work there would have to be some sort of standardisation in the HTML pages parsed. i.e table styles would have to be known in advance so that you could extract the table contents etc. Writing an HTML parser is definitely not a trivial task. Once you have a string representing the rows and columns of a specific table then you can still use the split method to retrieve the cell contents. If you could give me a more complete example of your HTML then maybe I could help you further.

              F 1 Reply Last reply
              0
              • W Wayne Gaylard

                Hi floodlight. The answer to this really depends on the HTML to parse. For a parser to work there would have to be some sort of standardisation in the HTML pages parsed. i.e table styles would have to be known in advance so that you could extract the table contents etc. Writing an HTML parser is definitely not a trivial task. Once you have a string representing the rows and columns of a specific table then you can still use the split method to retrieve the cell contents. If you could give me a more complete example of your HTML then maybe I could help you further.

                F Offline
                F Offline
                Floodlight
                wrote on last edited by
                #7

                Hi again Zimvbcoder, I can give you the exact string I will be parsing. You will see that some of the string contains the fields you helped me with in an earlier post... Okay, here's the string (it's one row from a HTML table) it's a little long lol, so you may need to paste into a HTML editor so you can see it clearly :) <tr><td class="aws"><a href="http://www.goauto.com.au/mellor/mellor.nsf/adredirect?readform&amp;admodel=outlander&amp;unid=3f98ba22ac6414b7ca2576e00004bad6&amp;make=general news&amp;model=&amp;time=0&amp;client=1&amp;adtype=useful&amp;page=news&amp;site=va" target="url">/mellor/mellor.nsf/adredirect?readform&admodel=outlander&unid=3f98ba22ac6414b7ca2576e00004bad6&make=general%20news&model=&time=0&client=1&adtype=useful&page=news&site=va</a></td><td>9</td><td>1.59 KB</td><td>9</td><td>9</td><td class="aws"><img src="/icon/other/hp.png" width="261" height="4"><br><img src="/icon/other/hk.png" width="249" height="4"><br><img src="/icon/other/he.png" width="261" height="4"><br><img src="/icon/other/hx.png" width="261" height="4"></td></tr>

                W 1 Reply Last reply
                0
                • F Floodlight

                  Hi again Zimvbcoder, I can give you the exact string I will be parsing. You will see that some of the string contains the fields you helped me with in an earlier post... Okay, here's the string (it's one row from a HTML table) it's a little long lol, so you may need to paste into a HTML editor so you can see it clearly :) <tr><td class="aws"><a href="http://www.goauto.com.au/mellor/mellor.nsf/adredirect?readform&amp;admodel=outlander&amp;unid=3f98ba22ac6414b7ca2576e00004bad6&amp;make=general news&amp;model=&amp;time=0&amp;client=1&amp;adtype=useful&amp;page=news&amp;site=va" target="url">/mellor/mellor.nsf/adredirect?readform&admodel=outlander&unid=3f98ba22ac6414b7ca2576e00004bad6&make=general%20news&model=&time=0&client=1&adtype=useful&page=news&site=va</a></td><td>9</td><td>1.59 KB</td><td>9</td><td>9</td><td class="aws"><img src="/icon/other/hp.png" width="261" height="4"><br><img src="/icon/other/hk.png" width="249" height="4"><br><img src="/icon/other/he.png" width="261" height="4"><br><img src="/icon/other/hx.png" width="261" height="4"></td></tr>

                  W Offline
                  W Offline
                  Wayne Gaylard
                  wrote on last edited by
                  #8

                  Hmmm. This will be quite complicated and will take more time than I am unfortunately able to give right now. Your best bet is to try a loop first splitting the string by and then by . This theoretically should give you an array of the table columns, although this is going to be messed around by property declarations in the column definitions i.e class="aws". This is going to be messy, especially with the double quotes in the html, so you won't be able to store this as a single string. Sorry I can't be of more help right now.

                  F 1 Reply Last reply
                  0
                  • W Wayne Gaylard

                    Hmmm. This will be quite complicated and will take more time than I am unfortunately able to give right now. Your best bet is to try a loop first splitting the string by and then by . This theoretically should give you an array of the table columns, although this is going to be messed around by property declarations in the column definitions i.e class="aws". This is going to be messy, especially with the double quotes in the html, so you won't be able to store this as a single string. Sorry I can't be of more help right now.

                    F Offline
                    F Offline
                    Floodlight
                    wrote on last edited by
                    #9

                    No worries mate, I appreciate you taking the time to look at it anyway :) I'll keep plugging away at it and see what trouble I can get myself in to, haha!

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups