Announcement

Collapse
No announcement yet.

Parse text on new line from script

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

    Parse text on new line from script

    I am attempting to parse out some text from a device (the thinking cleaner plugin for my Roomba) into discrete fields. This should be a simple task but I can't get it to work. The motivation for this can be seen here: https://forums.homeseer.com/showthread.php?t=173509

    The text is:
    Status: On homebase: Trickle Charging
    Model: 600
    Battery charge: 88 %
    Total cleaning distance: 299.30 KM
    Total cleaning time: 277 hours 8 minutes
    Last cleaning took: 0 hours 0 minutes

    This is the script that I have:

    Sub Main(parm as object)

    Dim sVal
    sVal = hs.devicestring(514)
    dim splitVal() as string
    splitVal = sVal.split(Chr(13))
    hs.WriteLog("Info", splitVal(0))
    hs.SetDeviceString(532, splitVal(0),True)
    End Sub

    The trouble is that it doesn't actually split on Chr(13) as I would expect. Instead I end up with everything in splitVal(0) and nothing in splitVal(1). I can replace this with ":" and it splits fine. I've also tried "/n", "/r", Chr(10), and Environment.NewLine without success. This seems very simple but I can't figure out where I'm going wrong. Any ideas?

    #2
    This might work:

    Code:
    Sub Main(parm as object)
    
    Dim sVal
    sVal = hs.devicestring(514)
    sVal = sVal.Replace(Chr(13), "")
    dim splitVal() as string
    splitVal = sVal.split(Chr(10))
    hs.WriteLog("Info", splitVal(0)) 
    hs.SetDeviceString(532, splitVal(0),True)
    End Sub
    Last edited by sparkman; February 27, 2017, 11:47 AM.
    HS 4.2.8.0: 2134 Devices 1252 Events
    Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

    Comment


      #3
      Now I get this in the log:

      Running script C:\Program Files (x86)\HomeSeer HS3\scripts\parseroomba2.vb :Exception has been thrown by the target of an invocation.Public member 'split' on type 'String()' not found.

      Comment


        #4
        I figured it out. The text was showing carriage returns and line feeds when I cut and pasted it into a text editor but the actual ascii codes in the original text simply had a <(nospace)br(nospace)> at the end of each line. If I split based on that it works.

        Thanks for the help.

        Edit: Had to put the (nospace) filler in there so it wouldn't get interpreted instead of printed.

        Comment


          #5
          Originally posted by acromion View Post
          Now I get this in the log:

          Running script C:\Program Files (x86)\HomeSeer HS3\scripts\parseroomba2.vb :Exception has been thrown by the target of an invocation.Public member 'split' on type 'String()' not found.
          Sorry, had messed up the code. It's fixed now, but looks like you have it resolved.

          Cheers
          Al
          HS 4.2.8.0: 2134 Devices 1252 Events
          Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

          Comment

          Working...
          X