what is the ruby function to remove all white spaces ? kinda like php's trim() ?
+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
2009-10-28 01:54:56
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
2009-10-28 01:56:20
+1
A:
Also don't forget:
$ s = " I have white space ".split
=> ["I", "have", "white", "space"]
Justicle
2009-10-28 01:58:06
+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
2009-10-28 02:13:00