Shop OBEX P1 Docs P2 Docs Learn Events
Split a string — Parallax Forums

Split a string

marclamarcla Posts: 19
edited 2008-05-18 17:11 in Propeller 1
Hello!
how do i split a string?

example:
mystr = hello····· 'Start string

ch1 = h············ 'Splited strings
ch2·= e
ch3 = l
ch4 = l
ch5 = o

Regards Martin

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-05-18 16:45
    A string is just an array of byte values that happen to be characters and, by convention, end with a zero byte. You can't directly assign strings, but you can copy them with BYTEMOVE (look in the Propeller manual for details). Here's a simple example:
    VAR byte helloStr[noparse][[/noparse] 9 ]
    
    PUB main
       BYTEMOVE(helloStr,6,string("hello"))   ' copy the string constant plus its zero byte
       if strsize(@helloStr) <> 5                    ' make sure the string is 5 characters
          ' do something
       if helloStr[noparse][[/noparse] 0 ] == "h"                          ' if so, check the first character
          ' do something
       if strcomp(@helloStr,string("hello"))     ' you can compare strings for equality this way
          ' do something
    
  • tpw_mantpw_man Posts: 276
    edited 2008-05-18 17:11
    @Mike Green and marcla

    The
    BYTEMOVE(helloStr,6,string("hello"))
    
    


    should be
    BYTEMOVE(@helloStr,string("hello"),6)
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1011, so be surprised!


    Advertisement sponsored by dfletch:
    Come and join us on the Propeller IRC channel for fast and easy help!
    Channel: #propeller
    Server: irc.freenode.net or freenode.net
    If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
    tongue.gif
Sign In or Register to comment.