Deleting an element from an array

Denis Koroskin 2korden at gmail.com
Tue Feb 3 05:08:49 PST 2009


On Tue, 03 Feb 2009 15:46:52 +0300, nobody <somebody at somewhere.com> wrote:

> What is the best way to completely remove an element from an array?
>
> For example you have an array:
> [1,2,3,4,5,6]
> and want to remove element "3" in such a way that the resulting array is:
> [1,2,4,5,6]
>
> Thanks.
>
>

import std.array;

auto arr = [0, 1, 2, 3, 4, 5];

int lowerBound = 2;
int upperBound = 4;

// erases elements [lowerBound, upperBound),
// total of upperBound - lowerBound elements
arr.erase(lowerBound, upperBound);

assert(arr == [0, 1, 4, 5]);



More information about the Digitalmars-d-learn mailing list