Text editing [Was: Re: #line decoder]
Sergey Gromov
snake.scaly at gmail.com
Thu Sep 25 08:26:40 PDT 2008
In article <gbg0uf$uka$1 at digitalmars.com>, bearophileHUGS at lycos.com
says...
> // loader3
> import std.stream;
> import std.string: split;
> void main() {
> auto fin = new BufferedFile("data2.txt");
> string[] first = fin.readLine().split();
> auto cols = new string[first.length];
> foreach (col, el; first)
> cols[col] ~= el.dup;
> foreach (string line; fin)
> foreach (col, el; line.split())
> cols[col] ~= el.dup;
> }
Specifically in this line:
> auto cols = new string[first.length];
you probably actually want "new string[][first.length]", otherwise you
simply get three huge strings.
My timing of your original sample is 9.8s (best out of 5 runs). The
fixed sample timing is 48.9s.
More information about the Digitalmars-d-announce
mailing list