Shop OBEX P1 Docs P2 Docs Learn Events
Strings and things (again!) — Parallax Forums

Strings and things (again!)

HughHugh Posts: 362
edited 2013-05-10 12:48 in Propeller 1
Hi,

I'm struggling with strings and things (again!)

I have a array of bytes, 'dataGS', that contains [67, 71, 77, 65, 66, 72, 73, 66] and that I would like to show on an LCD as a string. Another byte array, 'scratchPad', is used to shuffle things about.

What I thought I was doing was moving the first four characters of 'dataGS' into 'scratchpad' and then treat this as a string.
CON
dataGS[20] = [67, 71, 77, 65, 66, 72, 73, 66]

VAR
scratchpad[20]

...

PUB Main
bytefill(@scratchpad, 0, 20) 'Fill scratchpad with zeroes
bytemove(@scratchpad, @dataGS, 4)
lcd.str(scratchpad)

I've tried using lcd.str(@scratchpad).

Am I being naive that this will create a string (with a trailing zero, etc.,)?

Thanks
Hugh

Comments

  • SRLMSRLM Posts: 5,045
    edited 2013-05-10 12:16
    Why is scratchpad in CON? And I think it should be lcd.str(@scratchpad)

    Maybe you should move the arrays out of the CON section and into a DAT section. I'm looking through the manual (v1.2) and I don't see anything about arrays in the CON section. Instead, I'd try something like:
    DAT
       dataGS byte"My String"
       scratchpad byte 0[20]
    
  • HughHugh Posts: 362
    edited 2013-05-10 12:22
    Changed to VAR. :innocent:
    Sorry - my copy-and-paste error.
  • AribaAriba Posts: 2,690
    edited 2013-05-10 12:25
    Your PUB code should work (with lcd.str(@scratchpad), but you can not define byte arrays in CON.
    For initialized byte arrays you can use a DAT section, zero filled arrays are defined in a VAR section. In both cases you need the byte keyword:
    VAR
      byte scratchPad[20]
    DAT
    dataGS  byte  67, 71, 77, 65, 66, 72, 73, 66, 0
    

    Andy
  • Mike GreenMike Green Posts: 23,101
    edited 2013-05-10 12:26
    As long as you use "lcd.str(@scratchpad)" it should work. I prefer to leave out the BYTEFILL and do:
       bytemove(@scratchpad,@dataGS,4)
       scratchpad[4]~   ' add zero byte to end
       lcd.str(@scratchpad)
    
  • HughHugh Posts: 362
    edited 2013-05-10 12:48
    You are all right in all respects. It now works perfectly.

    Thank you!
Sign In or Register to comment.