From: Lucky Nl on
Hi
I Need small help that how to remove leading   tags
My text is:
str = "<p>Welcome to ruby &nbsp;&nbsp;</p> <p>&nbsp;&nbsp;</p>"
I want result is
str = "<p>Welcome to ruby</p>"

Can anybody help
--
Posted via http://www.ruby-forum.com/.

From: BruceL on
On Aug 2, 3:59 am, Lucky Nl <lakshmi2...(a)gmail.com> wrote:
> Hi
>   I Need small help that how to remove leading &nbsp; tags
>   My text is:
>      str = "<p>Welcome to ruby &nbsp;&nbsp;</p> <p>&nbsp;&nbsp;</p>"
>    I want result is
>      str = "<p>Welcome to ruby</p>"
>
> Can anybody help
> --
> Posted viahttp://www.ruby-forum.com/.

simply a.delete!("&nbsp;")
From: Rob Biedenharn on

On Aug 2, 2010, at 5:15 PM, BruceL wrote:

> On Aug 2, 3:59 am, Lucky Nl <lakshmi2...(a)gmail.com> wrote:
>> Hi
>> I Need small help that how to remove leading &nbsp; tags
>> My text is:
>> str = "<p>Welcome to ruby &nbsp;&nbsp;</p> <p>&nbsp;&nbsp;</p>"
>> I want result is
>> str = "<p>Welcome to ruby</p>"
>>
>> Can anybody help
>> --
>> Posted viahttp://www.ruby-forum.com/.
>
> simply a.delete!("&nbsp;")
>


Well, that's almost certainly not what the OP wants!

irb> str = "<p>Welcome to ruby &nbsp;&nbsp;</p> <p>&nbsp;&nbsp;</p>"
=> "<p>Welcome to ruby &nbsp;&nbsp;</p> <p>&nbsp;&nbsp;</p>"
irb> str.delete('&nbsp;')
=> "<>Welcome to ruy </> <></>"

Look at the documentation for String#delete

Then take a look at String#gsub

I suspect that you want to do two passes: one for '&nbsp;' and one for
empty paragraphs.

-Rob

Rob Biedenharn
Rob(a)AgileConsultingLLC.com http://AgileConsultingLLC.com/
rab(a)GaslightSoftware.com http://GaslightSoftware.com/