Announcement

Collapse
No announcement yet.

String manipulation help

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

    String manipulation help

    I'm using SeerAmp, which uses Winamp, and i'm trying to get some info pushed over to MainLobby.

    With seeramp i can get the "current song title" as text, but because of the way i set up my MP3 collection, the songs titles come out as:

    Cat Stevens - Peace Train

    as an example. it's always in the format: Artist - Song Title

    here is my script:

    Sub Main()

    Dim SeerAMP

    ' Current Song
    OldValue = hs.DeviceString("s1")
    Value = hs.plugin("SeerAmp").SongName(0)
    hs.SetDeviceString "s1",Value,TRUE
    End Sub


    how do i break that string up into "Title" and "Artist" to variables s1 and s2 ?

    Thanks,
    steve

    #2
    bwally

    There is a vbscript function called split that is designed for this purpose. This works:

    Code:
    artistsong = split("Cat Stevens - Peace Train"," - ",-1,1)
    msgbox artistsong(0)
    msgbox artistsong(1)
    artistsong(0) has "Cat Stevens" in it
    artistsong(1) has "Peace Train"

    Here are the MS Doc on it. I am spending more time here every day.....
    ms split() docs

    Run it and see. I cant test what you are doing, but this should work:

    Code:
    artistsong = split(hs.plugin("SeerAmp").SongName(0)," - ",-1,1)
    msgbox artistsong(0)
    msgbox artistsong(1)
    One side note, the second paratmeter, delimiter, is only supposed to have one character in it. I put in " - ", because that is what delimits your text. VBscript returns a script error to the log file, but runs the code anyway. If you make the delimiter a "-", the message goes away, but there will be a space after "Cat Stevens " and a space before " Peace Train". I would live with the error, more of a warning. It does work.

    Paul
    Last edited by pbibm; January 21, 2005, 02:27 AM.
    Paul

    Comment


      #3
      If you use the "-", you will get the spaces at the end of the artise, and the beginning ot the song name. To clear those spaces, you can use trim to remove leading and trailing spaces in a variable.

      For example:
      Code:
      If artistsong was "      Rod Stewart           "
         
         artistsong = trim (artistsong)
         
         Would make artistsong now be "Rod Stewart"
      Visit My Home Seer Site at:
      www.JohnWPB.com
      Created with LCARS

      Comment


        #4
        The Shoemaker and the Coding Elves!

        ... go to bed late and wake up to find these beautiful gifts


        thanks John and Paul (VBScript disciples)
        here's what i did and it works great:

        Sub Main()

        Dim SeerAMP
        Dim MyString, MyArray

        MyString = hs.plugin("SeerAmp").SongName(0)
        MyArray = Split(MyString, "-", -1, 1)

        ' Current Song Title
        OldValue = hs.DeviceString("s1")
        Value = trim(MyArray(0))
        hs.SetDeviceString "s1",Value,TRUE

        ' Current Artist
        OldValue = hs.DeviceString("s2")
        Value = trim(MyArray(1))
        hs.SetDeviceString "s2",Value,TRUE

        ' Current Song Length in Seconds
        OldValue = hs.DeviceString("s3")
        Value = hs.plugin("SeerAmp").TrackTime(0,1)
        hs.SetDeviceString "s3",Value,TRUE

        End Sub


        what i never realized until now was that Homeseer is pure VBScript. I was always thinking it was some hybrid. thanks for making that clear!

        steve.

        Comment


          #5
          at 6' 6" I am somewhere this side of "elf".

          However, you're welcome, glad it works
          Paul

          Comment


            #6
            Be careful using "-" instead of " - ". If an artist has a hyphen in the name, it will get split also, and then you'll have the second part of the artist name in your title array element spot.

            Comment

            Working...
            X