Sum informations in file....
Alexandre via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 10 07:49:15 PDT 2014
I have one file with a lot of numeric data... and I need to sum
all that data...
That is my actual code:
module main;
import std.stdio;
import std.file;
import std.conv : to;
int main(string[] args)
{
auto f = File("oi.txt");
auto r = f.byLine();
auto tot = 0;
foreach(line;r)
{
if(line[0] == '1')
tot += to!int(line[253..266]);
}
writeln(tot);
return 0;
}
I want to know if have a more better way to make this... maybe
using lambda or tamplates....
More information about the Digitalmars-d-learn
mailing list