Is there any way to only remove trailing white space from a string. I
have tried to use strip but that will also take off leading white space
and I want to keep that.
any help is appreciated
Is there any way to only remove trailing white space from a string. I
have tried to use strip but that will also take off leading white space
and I want to keep that.
any help is appreciated
Bob S. wrote:
Is there any way to only remove trailing white space from a string. I
have tried to use strip but that will also take off leading white space
and I want to keep that.any help is appreciated
irb(main):001:0> "sldkfj ".sub(/\s+\Z/, “”)
=> “sldkfj”
On Tue, Oct 14, 2008 at 1:46 PM, Bob S.
[email protected] wrote:
Is there any way to only remove trailing white space from a string. I
have tried to use strip but that will also take off leading white space
and I want to keep that.
String#rstrip will remove just the white space on the end (the “right”
side) of the string. Likewise, String#lstrip removes leading white
space only. And you already know about String#strip.
str = " string "
rightTrim = str.rstrip
=> " string"
leftTrim = str.lstrip
=> "string "
On Tue, 14 Oct 2008 14:46:43 -0400, Bob S.
Thank you all for your fast help.
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