Removing elements from dynamic arrays?

Bill Baxter dnewsgroup at
Sun Oct 29 23:57:10 PST 2006

How do I remove an element from a dynamic array?

    int[] a = [1,2,3,4,5];

I tried every syntax I could think of:

    a[3] = void;
    a[3..4] = void;
    a[3..4] = a[3..3];
    a[3] = [];
    a[3..4] = [];
    delete a[3];
    delete a[3..4];

The last one compiles, but fills a[0] with garbage.

I hope the answer isn't:

    a = a[0..3] ~ a[4..length];


More information about the Digitalmars-d-learn mailing list