From: Josh Cheek Date: 2012-08-05T02:02:09+09:00 Subject: Re: Stacking gsub! commands? --f46d04428d2cbbde0004c6739afd Content-Type: text/plain; charset=ISO-8859-1 On Fri, Aug 3, 2012 at 11:59 AM, Wayne Brisette wrote: > I have a script that I wrote that uses nokogiri to parse some HTML, the > results > I get back, I need to change several of the HTML entities (><&), I thought > I > could stack the gsub! commands so they would be something like this: > > my_string.gsub!(/>/, "<").gsub!(/ > but I found that work, so for now I'm using: > > my_string.gsub!(/>/, "<") > my_string.gsub!(/ > which works, but I'm sure is horribly inefficient. Is there a better way > to do > multiple global substitutions on a string? > > Why would it be inefficient? It looks like the same thing to me. --f46d04428d2cbbde0004c6739afd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Fri, Aug 3, 2012 at 11:59 AM, Wayne Brisette <wbrisett@att.net> wrote:
I have a script that I wrote that uses nokogiri to parse some HTML, the res= ults
I get back, I need to change several of the HTML entities (><&), = I thought I
could stack the gsub! commands so they would be something like this:

my_string.gsub!(/>/, "&lt;").gsub!(/</, "&gt;)=

but I found that work, so for now I'm using:

my_string.gsub!(/>/, "&lt;")
my_string.gsub!(/</, "&gt;)

which works, but I'm sure is horribly inefficient. Is there a better wa= y to do
multiple global substitutions on a string?


Why would it be inefficient? It looks like the same thing to me= .
--f46d04428d2cbbde0004c6739afd--