[racket-dev] `string-replace'

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Apr 19 08:36:58 EDT 2012

At Thu, 19 Apr 2012 08:26:20 -0400, Eli Barzilay wrote:
> Two hours ago, Laurent wrote:
> > Maybe also a `string-replace' could be useful, especially when one
> > does not want regexps and has special characters that need to be
> > quoted.
> Again, it's not clear how this shold look -- my guess:
>   (define (string-replace from str to)
>     (regexp-replace* (regexp-quote from) str to))
> If so, then I see a weak point for this too: on one hand it does
> compose two functions, but it does nothing more than that.  Also
> "characters that need to be quoted" seem suspicious to me -- can you
> clarify?  (I see "quoting" next to something that is supposed to be
> newbie-friendly, and my alarm goes off...)

Surely Laurent meant

   (define (string-replace str from to)
     (regexp-replace* (regexp-quote from) str (regexp-replace-quote to)))

which I think is a great addition.

Posted on the dev mailing list.