Assigning to char[N]

bearophile bearophileHUGS at lycos.com
Wed Feb 1 15:14:12 PST 2012


Ali Çehreli:

> what is the best way of modifying that array?

In your code it's the definition too that throws an exception:

void main() {
    char[100] a = "old content";
}


This works, but it's not nice:

import std.stdio;
void main() {
    char[100] a;
    string s1 = "old content";
    a[0 .. s1.length] = s1;
    writeln(a);
    string s2 = "new content";
    a[0 .. s2.length] = s2;
    writeln(a);
    a[0 .. "new content".length] = "new content";
    writeln(a);
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list