Propeller Manual

Table Of Contents
2: Spin Language Reference – STRING
Propeller Manual v1.1 · Page 205
STRING
Directive: Declare in-line string constant and get its address.
((PUB PRI))
STRING (StringExpression )
Returns: Address of in-line string constant.
StringExpression is the desired string expression to be used for temporary, in-line
purposes.
Explanation
The
DAT block is used often to create strings or string buffers that are reusable for various
purposes, but there are occasions when a string is needed for temporary purposes like
debugging or one-time uses in an object. The
T
STRING directive is meant for those one-time
uses; it compiles an in-line, zero-terminated string into memory and returns the address of
that string.
Using STRING
The
STRING directive is very good for creating one-time-use strings and passing the address of
that string to other methods. For example, assuming
PrintStr is a method created elsewhere.
PrintStr(string("This is a test string."))
The above example uses the STRING directive to compile a string, “This is a test string.”, into
memory and return the address of that string as the parameter for the fictitious
PrintStr
method.
If a string needs to be used in more than one place in code, it is better to define it in the
DAT
block so the address can be used multiple times.
T