tags:

views:

479

answers:

4

what is the ruby function to remove all white spaces ? kinda like php's trim() ?

+3  A: 
s = "I have white space".delete(' ')
Ed Swangren
+5  A: 

on the off chance you meant to ask for the function to remove white space from the beginning and end of a string ... your looking for strip

" clean up my edges    ".strip

would return

"clean up my edges"
jrhicks
That's the one I forgot about. I knew there was a method to remove whitespace which would do so by default if no arguments were passed. +1
Ed Swangren
+1  A: 

Also don't forget:

$ s = "   I have white space   ".split
=> ["I", "have", "white", "space"]
Justicle
+1  A: 

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 .

joel.neely
This is the correct answer
jrhicks