Previous: , Up: srfi strings spec   [Index]


2.8.3.14 Intertion, parsing, filtering and deleting

Function: string-replace str1 str2 start1 end1
Function: string-replace str1 str2 start1 end1 start2
Function: string-replace str1 str2 start1 end1 start2 end2

Return:

(string-append (substring/shared s1 0 start1)
               (substring/shared s2 start2 end2)
               (substring/shared s1 end1 (string-length s1)))

That is, the segment of characters in str1 from start1 to end1 is replaced by the segment of characters in str2 from start2 to end2. If start1 = end1, this simply splices the str2 characters into str1 at the specified index.

Examples:

(string-replace "The TCL programmer endured daily ridicule."
                "another miserable perl drone" 4 7 8 22)
⇒ "The miserable perl programmer endured daily ridicule."

(string-replace "It's easy to code it up in Scheme."
                "lots of fun" 5 9)
⇒ "It's lots of fun to code it up in Scheme."

(define (string-insert s i t)
  (string-replace s t i i))

(string-insert "It's easy to code it up in Scheme." 5 "really ")
⇒ "It's really easy to code it up in Scheme."
Function: string-tokenize str
Function: string-tokenize str token-set
Function: string-tokenize str token-set start
Function: string-tokenize str token-set start end

Split the string str into a list of substrings, where each substring is a maximal non–empty contiguous sequence of characters from the character set token-set.

This function provides a minimal parsing facility for simple applications. More sophisticated parsers that handle quoting and backslash effects can easily be constructed using regular–expression systems; be careful not to use string-tokenize in contexts where more serious parsing is needed.

(string-tokenize "Help make programs run, run, RUN!")
⇒ ("Help" "make" "programs" "run," "run," "RUN!")
Function: string-filter char/char-set/pred str
Function: string-filter char/char-set/pred str start
Function: string-filter char/char-set/pred str start end
Function: string-delete char/char-set/pred str
Function: string-delete char/char-set/pred str start
Function: string-delete char/char-set/pred str start end

Filter the string str, retaining only those characters that satisfy/do not satisfy the char/char-set/pred argument. If this argument is a procedure, it is applied to the character as a predicate; if it is a char–set, the character is tested for membership; if it is a character, it is used in an equality test.

If the string is unaltered by the filtering operation, these functions may return either str or a copy of str.


Previous: , Up: srfi strings spec   [Index]