[racket-dev] `string-replace'
On Thu, Apr 19, 2012 at 14:26, Eli Barzilay <eli at barzilay.org> 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))
>
I meant this:
(define (string-replace from str to)
(regexp-replace* (regexp-quote from) str (regexp-replace-quote to)))
(string-replace "(" "(a list)" "\\1") ; -> "\\1a list)"
Newbie-friendly (I meant regexp-quoted without the user seeing it) and easy
to use.
Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20120419/37c6db71/attachment-0001.html>