Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ruby Programming Language

remove all whitespaces in a string


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

"b@bla.de"

How can I achieve this?

Thanx

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

On Monday 28 May 2007 14:46:26 jochen kaechelin wrote:

gsub( ' ', '')

Stefano

Alle luned 28 maggio 2007, jochen kaechelin ha scritto:

On 5/28/07, jochen kaechelin <giss@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
> "b@bla.de"

> How can I achieve this?

  You can use String.gsub [1]

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

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

--
Luis Parravicini
http://ktulu.com.ar/blog/

Sorry, I meant

your_string.gsub(' ', '')

Stefano

Alle luned 28 maggio 2007, Stefano Crocco ha scritto:

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 schrieb:

It was I RoR mistake i made.
On 5/28/07, jochen kaechelin <giss@figgfrosch.de> wrote:

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.kakueki.com/

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:

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc