Equivalent to trim() PHP

Hello guys, I would like to know what is the equivalent to the function TRIM() from PHP in Rails 3 ?

Thank you.

strip()

Walter

Walter Davis wrote in post #1065220:

strip()

I bit more precisely that would be the "strip" method of the "String" class.

Example:

[1] pry(main)> str = " String with leading and trailing whitespace " => " String with leading and trailing whitespace " [2] pry(main)> str.strip => "String with leading and trailing whitespace"

I mention this because "strip" could have a different meaning in other classes.

Person#strip might have a different meaning entirely. :slight_smile:

One question, I have this follow string

" Hello \n\r How are you ? \n\r I'm fine ."

The strip gonna clean \n\r too ?

Thanks

No, it only acts on the outer bounds of the string. Have a look at the documentation on ruby-doc.org: Class: String (Ruby 1.9.3)

Walter

strip removes ONLY leading and trailing whitespaces, see:

Basically, PHP's trim() works the same.

If you want to remove whitespaces inside the string, you need to use `String#gsub` or `String#squeeze` (depending on what you want to achieve).