chickadee » srfi-135 » textual-replace

(textual-replace textual1 textual2 start1 end1 [start2 end2]) → textprocedure

Returns

(textual-append (subtextual textual1 0 start1)
(subtextual textual2 start2 end2)
(subtextual textual1 end1 (textual-length textual1)))

That is, the segment of characters in textual1 from start1 to end1 is replaced by the segment of characters in textual2 from start2 to end2. If start1 = end1, this simply splices the characters drawn from textual2 into textual1 at that position.

Examples:

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

(textual-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 (textual-insert s i t) (textual-replace s t i i))

(textual-insert "It's easy to code it up in Scheme." 5 "really ")
⇒ «It's really easy to code it up in Scheme.»

(define (textual-set s i c) (textual-replace s (text c) i (+ i 1)))

(textual-set "Text-ref runs in O(n) time." 19 #\1)
⇒ «Text-ref runs in O(1) time.»