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
···
--
Posted via http://www.ruby-forum.com/.
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
--
Posted via http://www.ruby-forum.com/.
Use delete_at - and read the documentation.
robert
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...
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/\.
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/.
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
2008/12/2 jazzez ravi <jazzezravi@gmail.com>:
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
Hi Park,
Thanks for your code. I will catch u soon with another issue
Thanks all,
P.Raveendran
--
Posted via http://www.ruby-forum.com/.
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
2008/12/2 Heesob Park <phasis@gmail.com>:
If there is no duplicate data, you can use values_at like this
(...)