Thread overview | |||||
---|---|---|---|---|---|
|
June 05, 2015 Append to array of strings within array of structs | ||||
---|---|---|---|---|
| ||||
I'm reading some text records from file and have a simple struct to hold records: struct Rec { string[] fileLines; } Rec someRecords; string someText; to append a new record I'm doing this: someRecords ~= Rec(); someRecords.fileLines ~= someText; but feel there might be a way to condense this to a single statement.. but how? Sorry about cat-on-keyboard posting-error (again!). |
June 05, 2015 Re: Append to array of strings within array of structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul | On Friday, 5 June 2015 at 19:44:29 UTC, Paul wrote:
> someRecords ~= Rec();
> someRecords.fileLines ~= someText;
You could condense them this way:
someRecords ~= Rec([someText]);
The Rec() can take arguments for the initial values, so an array starting with the someText should be cool
|
June 05, 2015 Re: Append to array of strings within array of structs | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | On Friday, 5 June 2015 at 19:46:36 UTC, Adam D. Ruppe wrote:
> The Rec() can take arguments for the initial values,
Yep, I realise that but couldn't figure out the syntax.... and I'm not sure I like it now that you've told me! :D
Thanks once again
Paul.
|
Copyright © 1999-2021 by the D Language Foundation