chickadee » srfi-130 » string-replace

string-replaceprocedure

Returns

(string-append (substring/cursors s1 (string-cursor-start s1) start1)
               (substring/cursors s2 start2 end2)
               (substring/cursors s1 end1 (string-cursor-end s1)))

That is, the segment of characters in s1 from start1 to end1 is replaced by the segment of characters in s2 from start2 to end2. If start1 = end1, this simply splices the s2 characters into s1 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."