PDA

View Full Version : Split a string



marcla
05-18-2008, 11:25 PM
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

Mike Green
05-18-2008, 11:45 PM
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[ 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[ 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_man
05-19-2008, 12:11 AM
@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 (http://www.mibbit.com)
http://forums.parallax.com/images/smilies/tongue.gif