I must be missing something obvious now, but I can't figure out how to add elements to a dynamic array in D.
I have tried this, without success:
string[] links;
foreach(link; someOtherArray) {
// Do something with link ...
links[] = link; // Trying here to add to the links array
}
and this:
string[] links;
int i = 0;
foreach(link; someOtherArray) {
// Do something with link ...
links[i] = link; // Trying here to add to the links array
i++;
}
What is the correct way to do this?
Use the concat operator: a ~ b or a ~= b;
string[] links;
foreach(link; arr) {
links ~= link;
}
The right side can be an individual element or another array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With