If I understand you right and all you want to do is to remove empty strings
from the end of the last array in an array of arrays, this should suffice:
irb(main):001:0> a = [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7",
"g", "", "", ""], ["", "h", "5", "", ""]]
=> [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "", "", ""],
["", "h", "5", "", ""]]
irb(main):002:0> while a.last.last == "" do
irb(main):003:1* a.last.pop
irb(main):004:1> end
=> nil
irb(main):005:0> a
=> [["a", "b", "", "c", "5"], ["d", "e", "f", "9.0", "7", "g", "", "", ""],
["", "h", "5"]]
irb(main):006:0>
HTH,
Felix
···
-----Original Message-----
From: list-bounce@example.com
[mailto:list-bounce@example.com] On Behalf Of Analogy Analogy
Sent: Tuesday, September 25, 2007 7:37 AM
To: ruby-talk ML
Subject: array manipulation
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/\.