Next: , Previous: SRFI-13 List/String Conversion, Up: SRFI-13


39.11.5 Selection

These procedures are called selectors, because they access information about the string or select pieces of a given string.

Additional selector procedures are documented in the Strings section (see String Selection), like string-length or string-ref.

string-copy is also available in core Guile, but this version accepts additional start/end indices.

— Scheme Procedure: string-copy str [start [end]]

Return a freshly allocated copy of the string str.

— Scheme Procedure: substring/shared str start [end]

Like substring, but the result may share storage with the argument str.

— Scheme Procedure: string-copy! target tstart s [start [end]]

Copy the sequence of characters from index range [start, end) in string s to string target, beginning at index tstart. The characters are copied left-to-right or right-to-left as needed — the copy is guaranteed to work, even if target and s are the same string. It is an error if the copy operation runs off the end of the target string.

— Scheme Procedure: string-take s n
— Scheme Procedure: string-take-right s n

Return the (shared) substring made from the first n characters of s.

— Scheme Procedure: string-drop s n
— Scheme Procedure: string-drop-right s n

Return the (shared) substring made from all but the first n characters of s.

— Scheme Procedure: string-pad s len [chr [start [end]]]
— Scheme Procedure: string-pad-right s len [chr [start [end]]]

Take characters from start to end from the string s and return a new string, left-padded by the character chr to length len.

If len is less than or equal to endstart, the result may share storage with s (or even be s).

— Scheme Procedure: string-trim s [skip [start [end]]]
— Scheme Procedure: string-trim-right s [skip [start [end]]]
— Scheme Procedure: string-trim-both s [skip [start [end]]]

Return the (shared) substring made by skipping over all characters on the left of s satisfying skip, which must be one of:

character ch
Trim characters equal to ch.
predicate (procecure) p
Trim characters that satisfy p.
character set cset
Trim characters in cset.

If omitted, skip defaults to char-set:whitespace. If no characters are skipped, return s directly.