[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

remove all whitespaces in a string

jochen kaechelin

5/28/2007 12:46:00 PM

I want to remove all whitespaces in a string.
I know strip to remove whitespaces at the beginning and the end
of the string.

example:

" bla @ bla. de "

should become

"bla@bla.de"

How can I achieve this?

Thanx

8 Answers

Markus Schirp

5/28/2007 12:51:00 PM

0


" bla @ bla.de ".gsub!(' ','')


On Monday 28 May 2007 14:46:26 jochen kaechelin wrote:
> I want to remove all whitespaces in a string.
> I know strip to remove whitespaces at the beginning and the end
> of the string.
>
> example:
>
> " bla @ bla. de "
>
> should become
>
> "bla@bla.de"
>
> How can I achieve this?
>
> Thanx



Stefano Crocco

5/28/2007 12:52:00 PM

0

gsub( ' ', '')

Stefano

Alle lunedì 28 maggio 2007, jochen kaechelin ha scritto:
> I want to remove all whitespaces in a string.
> I know strip to remove whitespaces at the beginning and the end
> of the string.
>
> example:
>
> " bla @ bla. de "
>
> should become
>
> "bla@bla.de"
>
> How can I achieve this?
>
> Thanx



Luis Parravicini

5/28/2007 12:53:00 PM

0

On 5/28/07, jochen kaechelin <gissmoh@figgfrosch.de> wrote:
> I want to remove all whitespaces in a string.
> I know strip to remove whitespaces at the beginning and the end
> of the string.
>
> example:
> " bla @ bla. de "
>
> should become
> "bla@bla.de"
>
> How can I achieve this?

You can use String.gsub [1]

irb(main):003:0> " bla @ bla. de ".gsub(/\s+/, '')
=> "bla@bla.de"


[1] http://dev.rubycentral.com/ref/ref_c_string...

--
Luis Parravicini
http://ktulu.co...

Stefano Crocco

5/28/2007 12:55:00 PM

0

Sorry, I meant

your_string.gsub(' ', '')

Stefano

Alle lunedì 28 maggio 2007, Stefano Crocco ha scritto:
> gsub( ' ', '')
>
> Stefano
>
> Alle lunedì 28 maggio 2007, jochen kaechelin ha scritto:
> > I want to remove all whitespaces in a string.
> > I know strip to remove whitespaces at the beginning and the end
> > of the string.
> >
> > example:
> >
> > " bla @ bla. de "
> >
> > should become
> >
> > "bla@bla.de"
> >
> > How can I achieve this?
> >
> > Thanx



jochen kaechelin

5/28/2007 1:02:00 PM

0

Markus Schirp schrieb:
> " bla @ bla.de ".gsub!(' ','')


Mmmh....I already used this syntax.......then there must be a
problem with my RoR code...

I will use the according ML.

Thanx.

jochen kaechelin

5/28/2007 1:21:00 PM

0

jochen kaechelin schrieb:
> I want to remove all whitespaces in a string.
> I know strip to remove whitespaces at the beginning and the end
> of the string.
>
> example:
>
> " bla @ bla. de "
>
> should become
>
> "bla@bla.de"
>
> How can I achieve this?
>
> Thanx
>
>

It was I RoR mistake i made.


Harry Kakueki

5/28/2007 1:52:00 PM

0

On 5/28/07, jochen kaechelin <gissmoh@figgfrosch.de> wrote:
> I want to remove all whitespaces in a string.
> I know strip to remove whitespaces at the beginning and the end
> of the string.
>
> example:
>
> " bla @ bla. de "
>
> should become
>
> "bla@bla.de"
>
> How can I achieve this?
>
> Thanx
>
>

This is probably slower, but here is another way you can try.

p " bla @ bla. de ".split(/\s+/).join

Harry

--

A Look into Japanese Ruby List in English
http://www.ka...

Florian Aßmann

5/31/2007 7:13:00 AM

0

Hi,

since Strings are Enumerable I created a singleton method that
overwrites the default one:

def str.each &block
self.split( // ).each &block
end
str.reject { |char| char =~ /\s/ }

But I don't know if this is going to brake anything...

Sincerely
Florian

Am 28.05.2007 um 15:51 schrieb Harry Kakueki:

> On 5/28/07, jochen kaechelin <gissmoh@figgfrosch.de> wrote:
>> I want to remove all whitespaces in a string.
>> I know strip to remove whitespaces at the beginning and the end
>> of the string.
>>
>> example:
>>
>> " bla @ bla. de "
>>
>> should become
>>
>> "bla@bla.de"
>>
>> How can I achieve this?
>>
>> Thanx
>>
>>
>
> This is probably slower, but here is another way you can try.
>
> p " bla @ bla. de ".split(/\s+/).join
>
> Harry
>
> --
>
> A Look into Japanese Ruby List in English
> http://www.ka...
>