This is a string “test1more32and444more22”.
How do I remove the numbers and replace them with a single whitespace?
I can do it but I’ll get a whitespace for each digit and consequently
have three whitespaces when there is three digits.
This is a string “test1more32and444more22”.
How do I remove the numbers and replace them with a single whitespace?
I can do it but I’ll get a whitespace for each digit and consequently
have three whitespaces when there is three digits.
2009/6/4 Pål Bergström [email protected]:
This is a string “test1more32and444more22”.
How do I remove the numbers and replace them with a single whitespace?
irb(main):005:0> “test1more32and444more22”.gsub(/[0-9]+/, " ")
=> "test more and more "
Hassan S. ------------------------ [email protected]
2009/6/4 Pål Bergström [email protected]
This is a string “test1more32and444more22”.
How do I remove the numbers and replace them with a single whitespace?
I can do it but I’ll get a whitespace for each digit and consequently
have three whitespaces when there is three digits.
You can try the following and please remember that “Programming Ruby”
book
is your
friend:
“test1more32and444more22”.gsub( /[0-9]+/, ’ ’ )
Good luck,
-Conrad
On Thu, Jun 4, 2009 at 5:01 PM, Conrad T. [email protected]
wrote:
“test1more32and444more22”.gsub( /[0-9]+/, ’ ’ )
or equivalently
“test1more32and444more22”.gsub( /\d+/, ’ ’ )
–
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
Rick Denatale wrote:
On Thu, Jun 4, 2009 at 5:01 PM, Conrad T. [email protected]
wrote:“test1more32and444more22”.gsub( /[0-9]+/, ’ ’ )
or equivalently
“test1more32and444more22”.gsub( /\d+/, ’ ’ )
–
Rick DeNataleBlog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale
Great. Thanks.
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