STRING   $!

STRING ( c --- <name> | --- addr c )

The word STRING defines an alphanumeric string variable.

The word STRING is preceded by a parameter indicating the maximum size of the variable string to define:

10 string a$

defines an alphanumeric variable a$ that can take ten characters or less.

The execution of a word defined by STRING deposits on the stack the address and the length of the string contained in its memory area. If the string variable has not yet been assigned, this length will be zero.

If the word string does not exist on your FORTH language version, here is how to define it:

\ define a strvar
: string  ( n --- names_strvar)
    create
        dup
        c,      \ n is maxlength
        0 c,    \ 0 is real length
        allot
    does>
        2 +
        dup 1 - c@
  ;

$! ( addr1 len1 addr2 len2 ---)

The word $! is used to store a character string in an alphanumeric variable. Example:

: example ( ---)
    s" Store a text in RCVdata"
    RCVdata $!
  ;

If the word $! does not exist on your FORTH language version, here is how to define it:

\ store str into strvar
: $!  ( str strvar ---)
    drop
    dup 2- c@       \ get maxlength of strvar
    rot min         \ keep min length
    2dup swap 1- c! \ store real length
    cmove           \ copy string
  ;