[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to remove empty element in an array

Li Chen

10/23/2006 5:27:00 PM

Hi all,

I have an array of [1,2,''] I want change it to [1,2]. I check the
document about Array but I cant't find a way to remove the empty
element. Any comments?

Thanks,

Li

--
Posted via http://www.ruby-....

2 Answers

Robert Klemme

10/23/2006 5:35:00 PM

0

Li Chen wrote:
> Hi all,
>
> I have an array of [1,2,''] I want change it to [1,2]. I check the
> document about Array but I cant't find a way to remove the empty
> element. Any comments?

http://ruby-doc.org/core/classes/Array.ht...

You should really get hold of your copy of the Pickaxe.

Regards

robert

Austin Ziegler

10/23/2006 5:36:00 PM

0

On 10/23/06, Li Chen <chen_li3@yahoo.com> wrote:
> Hi all,
>
> I have an array of [1,2,''] I want change it to [1,2]. I check the
> document about Array but I cant't find a way to remove the empty
> element. Any comments?

It's "[1, 2, <empty-string>]"? If so, then it's not an empty element.
If you have [1, 2, nil] then you can just use Array#compact or
Array#compact!. Otherwise, look at #delete_if.
--
Austin Ziegler * halostatue@gmail.com * http://www.halo...
* austin@halostatue.ca * http://www.halo...feed/
* austin@zieglers.ca