Strip comments from a string: Difference between revisions
Content added Content deleted
Line 613: | Line 613: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
Modern Forth advocates the use of stack strings. Stack strings are manipulated as an address and a length on the Forth DATA stack. As such they do not require memory copying for many forms of string functions making them fast. |
Modern Forth advocates the use of stack strings. Stack strings are manipulated as an address and a length on the Forth DATA stack. As such they do not require memory copying for many forms of string functions making them fast. Stack string functions typically return a stack string allowing concatenation of string functions. |
||
NOTES: |
NOTES: |
||
Line 619: | Line 619: | ||
1. SCAN is not a standard function but is common in most Forth systems as either a library function or resident. |
1. SCAN is not a standard function but is common in most Forth systems as either a library function or resident. |
||
2. -TRAILING is a resident function in most Forth systems. Shown for clarity. |
|||
2. FORTH style factoring means you can strip the comments and strip trailing spaces or not, as you see fit. |
|||
⚫ | |||
Or Concatenate the functions together as we did here. |
|||
⚫ | |||
<LANG FORTH>\ Rosetta Code Strip Comment |
<LANG FORTH>\ Rosetta Code Strip Comment |
||
: LASTCHAR ( addr len -- addr len c) 2DUP + C@ ; |
: LASTCHAR ( addr len -- addr len c) 2DUP + C@ ; |