Hello guys, I would like to know what is the equivalent to the function
TRIM() from PHP in Rails 3 ?
Thank you.
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 D. 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.
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
On Wed, 20 Jun 2012 15:54:25 +0200
Felipe Pieretti U. [email protected] wrote:
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 ?
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).
–
Sincerely yours,
Aleksey V. Zapparov A.K.A. ixti
FSF Member #7118
Mobile Phone: +34 677 990 688
Homepage: http://www.ixti.net
JID: [email protected]
*Origin: Happy Hacking!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs