From: "杨智宁" Date: 2012-07-20T03:18:14+09:00 Subject: Re: How to replace plain strings? --f46d0418275240f38304c532b042 Content-Type: text/plain; charset=ISO-8859-1 Try "a b c".sub("b", Regexp.escape("believe\\+me")) 2012/7/20 Albert Schlef > Rajarathnam p. wrote in post #1069363: > > Please try the following code which works "a b c".sub("b", > > 'believe\\\+me'). > > Since this string isn't hardcoded, I'll have to write a function to add > these slashes, and all this is becoming ugly: I don't want to waste time > on debugging. > > I finally solved my problem by doing: > > "a b c".sub("b") { "believe\\+me" } > > But I wonder if this is the "best" Ruby has to offer for my very humble > demands. > > -- > Posted via http://www.ruby-forum.com/. > > --f46d0418275240f38304c532b042 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Try "a b c".sub("b", Regexp.escape("believe\\+me&q= uot;))

2012/7/20 Albert Schlef <list= s@ruby-forum.com>
Rajarathnam p. wrote in post #1069363:
> Please try the following code which works "a b = c".sub("b",
> 'believe\\\+me').

Since this string isn't hardcoded, I'll have to write a funct= ion to add
these slashes, and all this is becoming ugly: I don't want to waste tim= e
on debugging.

I finally solved my problem by doing:

=A0 "a b c".sub("b") { "believe\\+me" }

But I wonder if this is the "best" Ruby has to offer for my very = humble
demands.

--f46d0418275240f38304c532b042--