substring(3scm) Scheme Programmer's Manual substring(3scm)

substring - copy part of a string

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

(substring string start end)

The substring procedure returns a newly allocated string formed from the characters of string beginning with index start (inclusive) and ending with index end (exclusive).

string must be a string, and start and end must be exact integer objects satisfying 0 ≤ startend(string-length string).

If start = end then the resulting empty string does not need to be newly allocated, as per eq?(3scm).

Chez Scheme, Loko Scheme, (more?)
There is a unique empty string object.

Returns a single string object.

(substring "SCHEMER" 0 6)  =>  "SCHEME"

This procedure is the same in all RnRS Scheme revisions since R2RS.

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
R7RS
The assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

string-copy(3scm)

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

This procedure was introduced in R2RS. Earlier revisions of Scheme ran on MacLisp, which had a substr function that it in turn copied from PL/I. Instead of the end argument, it had an optional length argument.

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.

2022-03-28