remove all whitespaces in a string

J

jochen kaechelin

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

"(e-mail address removed)"

How can I achieve this?

Thanx
 
S

Stefano Crocco

gsub( ' ', '')

Stefano

Alle luned=C3=AC 28 maggio 2007, jochen kaechelin ha scritto:
 
S

Stefano Crocco

Sorry, I meant

your_string.gsub(' ', '')

Stefano

Alle luned=C3=AC 28 maggio 2007, Stefano Crocco ha scritto:
 
J

jochen kaechelin

Markus said:
" 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.
 
J

jochen kaechelin

jochen said:
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

"(e-mail address removed)"

How can I achieve this?

Thanx

It was I RoR mistake i made.
 
H

Harry Kakueki

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

"(e-mail address removed)"

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
 
F

Florian Aßmann

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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top