Using iteration / method chaining / etc on multi-dimensional arrays
Uknown
sireeshkodali1 at gmail.com
Thu Apr 12 15:47:14 UTC 2018
On Thursday, 12 April 2018 at 15:38:34 UTC, Chris Katko wrote:
> I googled but couldn't find any clear solution.
>
> I've got a 2-D array of strings read from a text file I parsed.
> So it's like
>
> 0 1 15 0 0
> 2 12 1 0 0
> ...
> 0 1 0 10 0
>
> They come in with spaces, so I join into an array between them.
> But then the last ones have a newline \n on the end, which
> explodes the to! type conversion.
>
> If it was a single array, I could simply do:
>
> string [25] test;
>
> test.each((ref n) => n.stripRight());
>
> But how do you do that when it's a 2-D array?
>
> I'm looking not just for this case, but the generate case of
> iterating / applying filters to 2-D arrays.
>
> Thanks.
I think something like this would work:
test.each((ref s) => s.each((ref n) => n.stripRight()));
Essentially, get each 1D array from the 2D array, and then apply
the algorithms on that. There's probably a better way though
More information about the Digitalmars-d-learn
mailing list