Array deletion

Discussion in 'Ruby' started by jazzez ravi, Dec 2, 2008.

  1. jazzez ravi

    jazzez ravi Guest

    jazzez ravi, Dec 2, 2008
    #1
    1. Advertising

  2. 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
    Robert Klemme, Dec 2, 2008
    #2
    1. Advertising

  3. 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/.
    Vamsi Krishna, Dec 2, 2008
    #3
  4. jazzez ravi

    jazzez ravi Guest

    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/.
    jazzez ravi, Dec 2, 2008
    #4
  5. jazzez ravi

    Heesob Park Guest

    2008/12/2 jazzez ravi <>:
    > 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
    Heesob Park, Dec 2, 2008
    #5
  6. jazzez ravi

    jazzez ravi Guest

    jazzez ravi, Dec 2, 2008
    #6
  7. jazzez ravi

    Pit Capitain Guest

    2008/12/2 Heesob Park <>:
    > 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
    Pit Capitain, Dec 2, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SGFyYWxk?=

    Persistent cache contents after deletion

    =?Utf-8?B?SGFyYWxk?=, Feb 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    284
    =?Utf-8?B?SGFyYWxk?=
    Feb 19, 2004
  2. alanb

    FilePicker Deletion Access Denied

    alanb, Apr 26, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    368
    alanb
    Apr 26, 2004
  3. YouKnowIt
    Replies:
    0
    Views:
    381
    YouKnowIt
    May 12, 2004
  4. kkmonk
    Replies:
    0
    Views:
    367
    kkmonk
    Oct 4, 2010
  5. Replies:
    2
    Views:
    330
    Bart Van der Donck
    Dec 27, 2008
Loading...

Share This Page