substr
substr <string> <start> <len>
Extract a substring of up to len characters, starting at a 0-based
offset.
Arguments
<string>— the source text.<start>— an int, the 0-based index of the first character to copy. A negativestartis treated as0. Astartat or past the end of the string yields the empty string.<len>— an int, the maximum number of characters to copy. The result is clamped to the end of the string, so it may be shorter thanlen. A negativelenis treated as0.
Returns
A string — the copied characters. The source is never modified.
Examples
after command (say) {
do "say [substr "hello world" 0 5]"
}
This copies five characters from offset 0, so the mob says hello.
after command (say) {
do "say [substr "hello world" 6 100]"
}
The length runs past the end of the string, so it clamps: the mob says
world (everything from offset 6 onward).
See also
upper,lower— change the case of a string.words— split a string into a word iterable.int— parse a string as a number.- Strings and interpolation