Shop OBEX P1 Docs P2 Docs Learn Events
Writing Strings to DAT — Parallax Forums

Writing Strings to DAT

coryco2coryco2 Posts: 107
edited 2013-07-18 10:08 in Propeller 1
Is is possible to write more than one byte of data at a time in a DAT data block? I know I can do this:
PUB  MemTest
  byte[@myStr]:="T"

DAT
  myStr  byte  " ", 0

to write "T" to the data item myStr, so is there any simple way to write more than a single byte to the data item at a time, such as

byte[@myStr]:="Test String"

to store "Test String" in the myStr data item?

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-18 10:06
    You can initialize myStr to "Test String" as follows:
    DAT
      myStr byte "Test String", 0
    
    Or if you want to copy the string to myStr at run time you can do
    PUB MemTest
      bytemove(@myStr, string("Test String"),  12)
    DAT
      myStr byte 0[12]
    
    or you could use myStr as a pointer.
    PUB MemTest
      myStr := string("Test String")
    DAT
      myStr long 0
    
  • coryco2coryco2 Posts: 107
    edited 2013-07-18 10:06
    Ah! Figured it out:

    bytemove( @myStr, string("Test"), 4)
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-07-18 10:08
    In your example you need to copy 5 bytes to get the terminating NULL byte.
  • coryco2coryco2 Posts: 107
    edited 2013-07-18 10:08
    Thanks, Dave! :smile:
Sign In or Register to comment.