reading file byLine

Edwin van Leeuwen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 18 03:34:39 PDT 2015


On Friday, 18 September 2015 at 10:26:46 UTC, Namal wrote:
> Hello guys, is there a nice functional way to read the file 
> which is like
>
>
> 1,2,3,4,5,6
> 2,3,4,5,6,7
> 8,9,0,9,2,3
>
> line by line, split numbers and remove each ','
> convert it to int and save in a matrix int[][] arr?

Not tested, but I think the following should work:

auto matrix = str
   .byLine
   .map!((l) => l.split(",")    // Split each line
                 .map!(to!int)  // Turn into ints
                 .array)        // Return an array
   .array // Copy into an array




More information about the Digitalmars-d-learn mailing list