Announcement

Collapse
No announcement yet.

get last word in string for Sonos Player

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

  • get last word in string for Sonos Player

    I have a string heard by HS via Alexa. I would like to get the last word from the string so I can change Sonos Play

    For example the script gets this parm passed to it:

    run living room stop

    How do I get the STOP on the end?

    I would normally look for instrrev and find the last space and then use substr to
    get the last word. I didnt find any reference in the PDF for this.

    Thank you

  • #2
    This should do it for you - you'll need to change it to accept a parameter via than the string I have forced it to accept.

    Code:
    Sub Main(ByVal Parm As Object)
    
        Try
    
            Dim input as String = "run living room stop"
            Dim splInput() as string = input.split(chr(32))
            hs.writelog("", splInput(splInput.GetUpperBound(0)))
    
        Catch ex As Exception : hs.writelog("", "Exception: " & ex.message)
        End Try
    
    End Sub
    My Plugins:

    Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
    Yeelight 3P | Nanoleaf 3P

    Comment


    • #3
      Originally posted by mrhappy View Post
      This should do it for you - you'll need to change it to accept a parameter via than the string I have forced it to accept.

      Code:
      Sub Main(ByVal Parm As Object)
      
          Try
      
              Dim input as String = "run living room stop"
              Dim splInput() as string = input.split(chr(32))
              hs.writelog("", splInput(splInput.GetUpperBound(0)))
      
          Catch ex As Exception : hs.writelog("", "Exception: " & ex.message)
          End Try
      
      End Sub
      This works perfectly! Thanks again!

      Comment

      Working...
      X