From: "Wayne E. Seguin" Date: 2007-10-12T21:32:29+09:00 Subject: Re: How to delete specific characters from a string? ------=_Part_11653_22980280.1192192349585 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/12/07, Wayne E. Seguin wrote: > > I love that observation, great point Giles! Truly enjoyable. > class String def delete_indices(*indices, &block) indices.each do |index| yield self[index] if block_given? self[index] = '' end self end end Delete elements in this order: >> "Testing String".delete_indices(0,2,6,8) => "esing trng" Delete elements in a specified order and do something with them: >> "Testing String".delete_indices(0,2,6,8) {|value| p value.chr} "T" "t" "S" "i" => "esing trng" Delete a range and do something with it: >> "Testing String".delete_indices(0..4) {|value| p value} "Testi" => "ng String" Mix and match: >> "Testing String".delete_indices(0,2..4,8) {|value| p value} 84 "tin" 110 => "esg Strig" ~Wayne P.S. Just for fun. Giles already answered the OPs question IMO so why not play around with it? One of the things I love about Ruby is that you can actually enjoy playing around with the language itself! ------=_Part_11653_22980280.1192192349585--