Shop OBEX P1 Docs P2 Docs Learn Events
Using strings — Parallax Forums

Using strings

dk_akjdk_akj Posts: 37
edited 2004-08-05 21:10 in BASIC Stamp
Hi.

Just received my first stamp today, a BS2SX mounted on an education board.

I've spend the last hour trying to find out how it handles strings. But in my manual the word string is not to be found.

How do·I declare a variable og type string ?
How do I·assing a·value to the variable ?
How do I compare 2 strings ?

Thanks in advance
Anders

Comments

  • dk_akjdk_akj Posts: 37
    edited 2004-08-05 19:59
    //akj
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-05 21:10
    There is no string type in PBASIC, therefore you cannot compare strings (easily). String data can be stored in an array of bytes, and the STR modifier can be used to "print" these strings using DEBUG or SEROUT. To compare you would have to do it byte-by-byte.

    When strings are needed for displays, etc., they're typically stored in DATA statements. Like this:

    Msg1    DATA    "This is a text string", 0
    


    By making them zero-terminated, a simple subroutine can be used to "print" them:

    Print_String: 
      DO 
        READ eeAddr, char 
        eeAddr = eeAddr + 1 
        IF (char = 0) THEN EXIT 
        DEBUG char 
      LOOP 
      RETURN
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.