17.6.1.0245 /STRING slash-string STRING
( c-addr1 u1 n -- c-addr2 u2 )
Adjust the character string at c-addr1 by n characters. The resulting character string, specified by c-addr2 u2, begins at c-addr1 plus n characters and is u1 minus n characters long.
See:
Rationale:
/STRING is used to remove or add characters relative
to the current position in the character string. Positive values
of n will exclude characters from the string while
negative values of n will include characters to the
left of the string.
S" ABC" 2 /STRING 2DUP TYPE \ outputs "C"
-1 /STRING TYPE \ outputs "BC"
Testing:
T{ s1 5 /STRING -> s1 SWAP 5 + SWAP 5 - }T
T{ s1 10 /STRING -4 /STRING -> s1 6 /STRING }T
T{ s1 0 /STRING -> s1 }T
T{ s1 10 /STRING -4 /STRING -> s1 6 /STRING }T
T{ s1 0 /STRING -> s1 }T
ContributeContributions
JimPeterson [203] Possible Reference ImplementationSuggested reference implementation2021-05-21 17:58:29
Would this be a sufficient reference implementation?:
: /STRING DUP >R - SWAP R> CHARS + SWAP ;
Are there no checks for when u2 might go negative (or, really, wraps around, as it's considered unsigned)?