From: Robert Dober Date: 2007-09-26T00:12:31+09:00 Subject: Re: array manipulation On 9/25/07, Analogy Analogy wrote: > Hi Folks, > > I have a general newbie type question > Say I have a 2D array that I obtained from an external program: > > array = [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "", > "", ""], ["", "h", "5", "", ""]] > > > Is there a way to remove just the last two empty strings ("") in the > last element, so the array will look like this: > > array = [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "", > "", ""], ["", "h", "5"]] > > I've looked at array.compact, but this removes all of the empty > strings(""), plus I'd have to flatten the array to 1D, which is no good. > Thanks in advance! > -- > Posted via http://www.ruby-forum.com/. > > 2.times{ array.last.pop } but is this really what you want? I mean are you not up to something more general? for example: 2.times{ array.last.pop if array.last.empty? } do you see what I mean? Cheers Robert -- I'm an atheist and that's it. I believe there's nothing we can know except that we should be kind to each other and do what we can for other people. -- Katharine Hepburn