Next: , Previous: , Up: Strings   [Contents][Index]


6.6.5.12 Miscellaneous String Operations

Scheme Procedure: xsubstring s from [to [start [end]]]
C Function: scm_xsubstring (s, from, to, start, end)

This is the extended substring procedure that implements replicated copying of a substring of some string.

s is a string, start and end are optional arguments that demarcate a substring of s, defaulting to 0 and the length of s. Replicate this substring up and down index space, in both the positive and negative directions. xsubstring returns the substring of this string beginning at index from, and ending at to, which defaults to from + (end - start).

Scheme Procedure: string-xcopy! target tstart s sfrom [sto [start [end]]]
C Function: scm_string_xcopy_x (target, tstart, s, sfrom, sto, start, end)

Exactly the same as xsubstring, but the extracted text is written into the string target starting at index tstart. The operation is not defined if (eq? target s) or these arguments share storage – you cannot copy a string on top of itself.

Scheme Procedure: string-replace s1 s2 [start1 [end1 [start2 [end2]]]]
C Function: scm_string_replace (s1, s2, start1, end1, start2, end2)

Return the string s1, but with the characters start1end1 replaced by the characters start2end2 from s2.

Scheme Procedure: string-tokenize s [token_set [start [end]]]
C Function: scm_string_tokenize (s, token_set, start, end)

Split the string s into a list of substrings, where each substring is a maximal non-empty contiguous sequence of characters from the character set token_set, which defaults to char-set:graphic. If start or end indices are provided, they restrict string-tokenize to operating on the indicated substring of s.

Scheme Procedure: string-filter char_pred s [start [end]]
C Function: scm_string_filter (char_pred, s, start, end)

Filter the string s, retaining only those characters which satisfy char_pred.

If char_pred is a procedure, it is applied to each character as a predicate, if it is a character, it is tested for equality and if it is a character set, it is tested for membership.

Scheme Procedure: string-delete char_pred s [start [end]]
C Function: scm_string_delete (char_pred, s, start, end)

Delete characters satisfying char_pred from s.

If char_pred is a procedure, it is applied to each character as a predicate, if it is a character, it is tested for equality and if it is a character set, it is tested for membership.

The following additional functions are available in the module (ice-9 string-fun). They can be used with:

(use-modules (ice-9 string-fun))
Scheme Procedure: string-replace-substring str substring replacement

Return a new string where every instance of substring in string str has been replaced by replacement. For example:

(string-replace-substring "a ring of strings" "ring" "rut")
⇒ "a rut of struts"

Next: , Previous: , Up: Strings   [Contents][Index]