Announcement

Collapse
No announcement yet.

Parse String and extract sections

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Parse String and extract sections

    Hello,

    I have a regex which runs and extracts an address from within a string (pager message), and the format of the address is normally something like this:

    xx TERRELL CL ENDEAVOUR HILLS /ISAAC SMITH CR where the xx is the street number, and /ISAAC SMITH CR represents the nearest cross road / road.

    Below i have copied some code I am using in my script, but for some reason it does not appear to be breaking the string down correctly, what I am trying to do is have the address be anything before / (if / exists in the string), then the cross road be anything between / and // if they exist (e.g. there are two cross roads). I then use this address to geocode latitude and longitude and go from there.

    The strange thing though, is that alot of the time the geocoding is pulling up different streets that it thinks i mean, which is because my script is keeping the /STREET crossroad there, so for example instead of sending for geocoding xx TERRELL CL ENDEAVOUR HILLS it sends xx TERRELL CL ENDEAVOUR HILLS /ISAAC SMITH CR which means that the geocoder things i mean ISAAC SMITH CR rather than TERRELL CL. Have i missed something in my script that would cause this to error up?

    The only exception to the above, is if there is a CNR in the string, then the address format is normally STREET 1 RD/STREET 2 RD where i do actually want to not strip the / out etc.

    Thanks!

    PHP Code:
    If Instr(1ExtractedAddress"/") > and Instr(1ExtractedAddress"CNR") < 0  then
                      CleanedAddress 
    ExtractedAddress.Substring(0ExtractedAddress.IndexOf("/"))
                      
    CrossRoads ExtractedAddress.Substring(ExtractedAddress.IndexOf("/"),ExtractedAddress.Length ExtractedAddress.IndexOf("/"))
                      
    Dim MainAddress() as String ExtractedAddress.split("/")
                      
    hs.WriteLog("Guessed-Address""Guessed Address = " MainAddress(0))
                      elseIf 
    Instr(1ExtractedAddress"/") > and Instr(1ExtractedAddress"CNR") > 0  then
                      CleanedAddress 
    ExtractedAddress
                      
                      
    else
                      
    CleanedAddress ExtractedAddress
                      CrossRoads 
    ""
                      
    end if 
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    #2
    Just wondering if anyone had any ideas with this, ignoring the above section I can easily look for a CNR in the string then just take the whole string as is, but how can I take the string and extract the crossroads.

    pseudocode, but still:

    String = 123 EXAMPLE RD MELBOURNE /FOURTH RD //CHURCH RD

    if instr "CNR' > 1 then
    Address = Full String
    First Cross Road = ""
    Second Cross Road = ""

    elseif Instr "\" > 1 and Instr "CNR" < 1 and Instr "\\" < 1 then
    Address = String from start of string until first \ (e.g. 123 EXAMPLE RD MELBOURNE)
    First Cross Road = String after \ (e.g. FOURTH RD)
    Second Cross Road = String after \\ (e.g. Null / "")

    elseif Instr "CNR" < 1 and Instr "\" > 1 and Instr "\\" > 1 then
    Address = String from start of string until first \ (e.g. 123 EXAMPLE RD MELBOURNE)
    First Cross Road = String between \ and \\ (e.g. FOURTH RD)
    Second Cross Road = String after \\ (e.g. CHURCH ST)

    Thanks
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    Comment


      #3
      Sorry i am very short on time at the moment but this my get you on the right track. You can use something like this
      Code:
        Dim Words as Array
        Dim LastWord As String
      
        Words = Split(strRAW, "/")
        LastWord = UCase(Words(UBound(Words)))
      Or use Words(0) for 1e word, Words(1) for second ect.
      And do a check on Words.lenght to skip the //
      With Ubound() you can check how many items there are in the array
      More info here http://www.w3schools.com/vbscript/func_split.asp
      - Bram

      Send from my Commodore VIC-20

      Ashai_Rey____________________________________________________________ ________________
      HS3 Pro 3.0.0.534
      PIugins: ZMC audio | ZMC VR | ZMC IR | ZMC NDS | RFXcom | AZ scripts | Jon00 Scripts | BLBackup | FritzBox | Z-Wave | mcsMQTT | AK Ikea

      Comment


        #4
        Thanks for the advice, I was able to use Strings.Left, Strings.Mid and Strings.Right along with IndexOf("/") to get it to work.

        Thanks for the tips!
        HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

        Facebook | Twitter | Flickr | Google+ | Website | YouTube

        Comment


          #5
          Do you have the final code?

          Comment

          Working...
          X