Announcement

Collapse
No announcement yet.

String extract and Array Lookup

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

    String extract and Array Lookup

    Hello Wonderful Coders

    A two part question for you, but to make it easier i will start with the first and work from there. I have a string (pager message) which has a location code on it, it also normally has an address but because the address always varies, and sometimes is difficuilt to parse out i wanted to try and pull out the location code (e.g. NEWB1) where the location code is NEWB, and then compare this to a list i have (CSV) where it has the Location Code, and Location on it.

    So for example it would be like this:

    LocationCode Location
    TOOM Toomuc Valley
    PKHM Pakenham
    NEWB Newberry

    The list is a lot bigger than that (about 1600 entries), but what i wanted to know, is does someone have an idea on the easiest way i could extract (through Regex i guess) the location code, and then compare that to the table / csv file to get the Location.

    So for example say i feed into a vb file TOOM, it would output Toomuc Valley.


    The end goal of this entire project is to be able to look at fire calls through the paging system, see which assignment area they relate to, and then compare (using snevl latitude) how close I am to the assignment area, and if i am within a certian number of km to send an email warning me something is up ahead. Kind of like an accident avoidance system i guess.

    Ideally i would use the address, since it would be better to avoid the street rather than town level, but for proof of concept it should work on town level.

    Thanks Guys.
    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
    I think you would be better off opening the CSV file as a database connection and performing an SQL query based on your input to try and find the output, I am sure I used to do something similar and it worked OK. I think I have some code that deals with this very thing, I will try and find it.

    Comment


      #3
      This is a quick and dirty way to do it and assumes that your CSV only has 2 columns:

      PHP Code:
      Sub Main(ByVal Parm As Object)

      Dim LC As String="NEWB1"
      Dim P As New System.Text.RegularExpressions.Regex("\d")
      Dim Location As String GetLocation(P.Replace(LC,""))
      hs.writelog(LC,Location)

      end sub

      Function GetLocation(ByVal LC As String)
      Dim File As String=hs.GetAppPath "\data\your.csv" ' path to your csv file
      Dim Result As String = My.Computer.FileSystem.ReadAllText(file) & vbcrLf
      Return hs.stringItem(hs.stringItem(Mid(Result,Instr(1,Result,LC,1)),1,vbcrlf),2,",").Trim
      End function 
      Jon

      Comment

      Working...
      X