Shop OBEX P1 Docs P2 Docs Learn Events
Function SUBSTR: set pointer (@) to defined position and read following n bytes — Parallax Forums

Function SUBSTR: set pointer (@) to defined position and read following n bytes

HerdyHerdy Posts: 6
edited 2008-07-02 21:35 in Propeller 1
I am trying to find an intelligent solution of reading out a defined string list stored in BYTEs, separated by the zero-bit. I tried to do this with the following code. I may be confusing pointers or reading single bytes. However this did not work. Maybe you have a hint to this.

[b]DAT[/b]
  mnu byte "Menu 1",0,"Menu 2",0,"Menu 3",0,"Menu 4"
 
[b]PUB[/b] main
                                                
  lcd.cls

  lcd.output([b]substr(@mnu,1)[/b],0,3,16)    ' output substring onto LCD
 
[b]PRI[/b] [b]substr[/b](strAddr,ndx)
  repeat ndx                             ' loops ndx times
    repeat strAddr.byte <> $00           ' loops as long byte is not <> $00
      strAddr++                          ' increments pointer by 1
  result := strAddr.byte                 ' return result



Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-07-02 21:35
    "strAddr.byte" is the wrong notation. It provides the least significant byte of "strAddr" as a value. You want "byte[noparse][[/noparse]strAddr]" and you want to return "strAddr + 1". The last choice needs to have a zero byte for a terminator.
Sign In or Register to comment.