From: Brian Candler Date: 2012-05-01T16:44:49+09:00 Subject: Re: delete character from array Robert Klemme wrote in post #1059013: > No need for a block. I used the block form because I believe it to be clearer (no issues about backslash escaping) > But this deletes every third _character_. It will work the same for > OP's strings but may not work in other cases. For really deleting > _letters_ we could do > > irb(main):004:0> c=0; a.gsub(/\w/) {|ch| (c+=1) % 3 == 0 ? nil : ch} > => "th quck ron fx jmp ovr te lzy og" Ah, but aren't all those repeated method calls for integer addition and modulo arithmetic going to be inefficient? :-) You could use a single gsub instead: >> a.gsub(/(\w[^\w]*\w[^\w]*)\w([^\w]*)/, '\\1\\2') => "th quck ron fx jmp ovr te lzy og" -- Posted via http://www.ruby-forum.com/.