Counted strings store the length as byte at the address pointed to, followed by the bytes of the string. Their possible length is severely limited, and you cannot create a substring in-place without destroying the input string. Therefore we recommend against using counted strings. Nevertheless, if you have to deal with counted strings, here are some words for that:
count
( c-addr1 – c-addr2 u ) core “count”
c-addr2 is the first character and u the length of the counted string at c-addr1.
The following word has no useful interpretation semantics (unlike
s"
) and no interpretive counterpart (unlike [char]
), so
you should use it only inside colon definitions (if at all):
C"
( compilation "ccc<quote>" – ; run-time – c-addr ) core-ext “c-quote”
Compilation: parse a string ccc delimited by a "
(double quote). At run-time, return c-addr which
specifies the counted string ccc. Interpretation
semantics are undefined.
place
( c-addr1 u c-addr2 – ) gforth-experimental “place”
Create a counted string of length u at c-addr2 and
copy the string c-addr1 u into that location. Up to 256
bytes starting at c-addr2 will be written, so make sure
that the buffer at c-addr2 has that much space (or check
that u+1 does not exceed the buffer size before calling
place
)
string,
( c-addr u – ) gforth-0.2 “string,”
puts down string as cstring