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. -- Posted via http://www.ruby-forum.com/.
Hassan Schroeder
2009-Jun-04 21:01 UTC
Re: Replace numbers and leave one single whitespace
2009/6/4 Pål Bergström <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> 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 " HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2009/6/4 Pål Bergström <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>> > 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> > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Jun 4, 2009 at 5:01 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > 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/rickdenataleGreat. Thanks. :-) -- Posted via http://www.ruby-forum.com/.