Shop OBEX P1 Docs P2 Docs Learn Events
More String Concaternation — Parallax Forums

More String Concaternation

HeavyHeavy Posts: 6
edited 2010-07-06 17:22 in Propeller 1
Ok so I'm new at this propeller stuff. I want to join 2 strings into a third string, but I have failed miserably at all attempts. Here's my code.

Here's the relevant parts of my code:


VAR
·· byte nextfile·
·· byte newfile[noparse][[/noparse]8]
·· byte fileext

PUB start· | cog_ID
fileext := String(".csv")
nextfile := String("test")
bytemove(@newfile ,@nextfile,strsize(nextfile))
bytemove(@newfile + 4,@fileext,strsize(fileext) + 1)


This is what I get on the Serial terminal:
nextfile =test
fileext =
newfile =test

What I want is for newfile to be the combination of nextfile and fileext.

Any help would be appreciated. Thanks
·

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-07-05 22:23
    The string function returns a word address. Your fileext and nextfile variables are bytes (i.e. too short). Make them word variables. Since nextfile and fileext are already addresses, you do not want to prepend an @ to them in your bytemove commands. Also, newfile needs to be one byte longer to accommodate the zero terminator.

    -Phil
  • HeavyHeavy Posts: 6
    edited 2010-07-05 23:03
    Thanks for your help. I was wondering if you could help with my next problem.
    How would I go about joining the two strings if nextfile is a number. I've dowloaded Numbers.spin , but I can't seem to get Num.ToStr to work.

    Post Edited (Heavy) : 7/5/2010 11:22:05 PM GMT
  • AribaAriba Posts: 2,690
    edited 2010-07-06 00:43
    Try this:

      fileext := String(".csv")
      nextfile := num.toStr( 123, num#DEC)
      bytemove(nextfile + strsize(nextfile),fileext,strsize(fileext) + 1)
    
      term.str(nextfile)   'print result on terminal
    
    



    This uses the stringbuffer in the numbers object, which anyway reserves memory, for the resulting string. nextfile points to this string.
    123 is the number to convert, you can also use a variable instead.
    nextfile and fileext are long variables

    Andy
  • HeavyHeavy Posts: 6
    edited 2010-07-06 17:22
    Thanks, That got it. you all been a lot of help
Sign In or Register to comment.