From: Robert Dober Date: 2007-07-20T20:49:07+09:00 Subject: Re: Is there a replacement for sub? On 7/20/07, Martin DeMello wrote: > On 7/20/07, Robert Dober wrote: > > > > I was reading this whole thread and I kind of think to be dreaming, I > > must have missed something obvious!!! > > Anyway maybe this is was OP wants, well I think it is ;) > > > > 529/29 > irb > > irb(main):001:0> a='a b c d e f' > > => "a b c d e f" > > irb(main):002:0> a.gsub!(" ","") > > Nope, he wants a method that only replaces the first n occurrences of > the pattern. gsub will not do this - you need to run sub in a loop. > (This is where perl's "continue matching where you left off" would > have been a nice optimisation) I knew I missed something but I did not see what, sorry.... > > martin > > -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck