Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Array deletion

Reply
Thread Tools

Array deletion

 
 
jazzez ravi
Guest
Posts: n/a
 
      12-02-2008
Hi All,

have an array like,

a=["one","xcxc","two","dadasd","three","hgfhgfh"]

I want to delete the index of a[1],a[3] and so on...


Thanks in advance,
P.Raveendran
http://raveendran.wordpress.com
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      12-02-2008
On 02.12.2008 07:25, jazzez ravi wrote:
> Hi All,
>
> have an array like,
>
> a=["one","xcxc","two","dadasd","three","hgfhgfh"]
>
> I want to delete the index of a[1],a[3] and so on...


Use delete_at - and read the documentation.

robert
 
Reply With Quote
 
 
 
 
Vamsi Krishna
Guest
Posts: n/a
 
      12-02-2008
jazzez ravi wrote:
> Hi All,
>
> have an array like,
>
> a=["one","xcxc","two","dadasd","three","hgfhgfh"]
>
> I want to delete the index of a[1],a[3] and so on...
>
>
> Thanks in advance,
> P.Raveendran
> http://raveendran.wordpress.com


array.delete_at(index). use this to delete particular indexes in an
array.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
jazzez ravi
Guest
Posts: n/a
 
      12-02-2008
Hi Vamsi and Robert,

delete_at(index) is useful when need to delete one data. But i want to
delete series like 1,3,5,7. Currently i am using loop for it. Any other
good code for it.

I tried Array.delete_at(1,3,7,9) --> Like this



Thanks,
P.Raveendran
http://raveendran.wordpress.com

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

 
Reply With Quote
 
Heesob Park
Guest
Posts: n/a
 
      12-02-2008
2008/12/2 jazzez ravi <(E-Mail Removed)>:
> Hi Vamsi and Robert,
>
> delete_at(index) is useful when need to delete one data. But i want to
> delete series like 1,3,5,7. Currently i am using loop for it. Any other
> good code for it.
>
> I tried Array.delete_at(1,3,7,9) --> Like this
>
>

If there is no duplicate data, you can use values_at like this

a = a - a.values_at(1,3,5,7)

Regards,

Park Heesob

 
Reply With Quote
 
jazzez ravi
Guest
Posts: n/a
 
      12-02-2008
Hi Park,

Thanks for your code. I will catch u soon with another issue


Thanks all,

P.Raveendran
http://raveendran.wordpress.com
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Pit Capitain
Guest
Posts: n/a
 
      12-02-2008
2008/12/2 Heesob Park <(E-Mail Removed)>:
> If there is no duplicate data, you can use values_at like this
> (...)


Or apply Array#- to the indexes. This works with duplicate data, too:

a.values_at(*((0...a.size).to_a - [1, 3, 5, 7]))

Regards,
Pit

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to speed up the deletion of multidimensional array in C++ kkmonk C++ 0 10-04-2010 09:14 PM
list box with items for deletion passed from php array student4lifer@gmail.com Javascript 2 12-27-2008 11:21 AM
Google History Deletion Frank Adey Firefox 1 02-23-2005 05:24 PM
Deletion of read messages in newsgroup heim Firefox 10 12-12-2004 12:39 PM
how to:multi-deletion of items in files or programs don Microsoft Certification 2 08-10-2004 03:22 PM



Advertisments