From: "Wayne E. Seguin" Date: 2007-10-12T12:44:00+09:00 Subject: Re: How to delete specific characters from a string? ------=_Part_10858_9837671.1192160640498 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/11/07, Giles Bowkett wrote: > > I think the OP was looking for a method on String itself, but the > whole point of Ruby is that if the language doesn't have the features > you want, you just add the features to the language. > > class String > def delete_n_from_p(n, p) > n.times do > self[p] = '' > end > self > end > end > > >> "muppet".delete_n_from_p(2,3) > => "mupt" > > That makes it easy to reuse the functionality. > > -- > Giles Bowkett > This little problem is quite enjoyable: class String def delete_indices(*indices) indices.each do |index| self[index] = '' end self end end >> a = "Testing String" => "Testing String" >> a.delete_indices(0,3,6,8) => "estng trng" HTH, ~Wayne ------=_Part_10858_9837671.1192160640498--