Shop OBEX P1 Docs P2 Docs Learn Events
understanding string manipulations — Parallax Forums

understanding string manipulations

NamNoriNamNori Posts: 4
edited 2014-01-12 21:35 in Propeller 1
Hello:

In attempting to do some string manipulation, I quickly figured out that I'm not sure of what I'm doing.

I had wanted to concatenate 2 strings into a single variable, and found other posts on the forum showing how to do so with some ByteMove statements. But it's not working for me; obviously I went south somewhere here... I was attempting to simply concatenate src1 with src2 into dest. My first ByteMove statement works, but the second one doesn't do anything. And by putting the addresses out to the serial terminal, I see that when it's all done, both the dest and the src1 variables have the same address? Doesn't seem right to me. I've played with adding/removing the "@" to/from the variables within ByteMove, and it only seems to work with @ in place like it is below.

I'm probably not understanding some fundamental aspect here, and am hoping somebody can clear up my misunderstanding.

thanks!
-marc
CON
  _clkmode  = xtal1 + pll16x           
  _xinfreq  = 5_000_000                

OBJ
  PST           : "Parallax Serial Terminal"

VAR
  byte dest[10]
  byte src1
  byte src2

PUB Main

  PST.Start(115200)                                  
  PST.Home
  PST.Clear
  
  Src1 := String("abc")
  Src2 := String("def")

  PST.Str(String("Src1: "))
  PST.Str(src1)
  PST.NewLine
  PST.Str(String("Src2: "))
  PST.Str(src2)
  PST.NewLine

  PST.Hex(src1, 2)
  PST.NewLine
  PST.Hex(src2, 2)
  PST.NewLine
  
  ByteMove(@dest, @src1, StrSize(src1))
  ByteMove(@dest + StrSize(src1), @src2, StrSize(src2) + 1)
  
  PST.Str(String("Dest: "))
  PST.Str(dest)
  PST.NewLine
  PST.Hex(dest, 2)
  PST.NewLine
  PST.Hex(src1, 2)

Comments

Sign In or Register to comment.