Ruby function to remove all white spaces?

gpwu picture gpwu · Oct 28, 2009 · Viewed 568.1k times · Source

What is the Ruby function to remove all white spaces? I'm looking for something kind of like PHP's trim()?

Answer

joel.neely picture joel.neely · Oct 28, 2009

If you want to remove only leading and trailing whitespace (like PHP's trim) you can use .strip, but if you want to remove all whitespace, you can use .gsub(/\s+/, "") instead .