Multidimensional dynamic array of strings initialized with split()

Ludovit Lucenic llucenic at gmail.com
Wed Sep 4 15:57:34 PDT 2013


Hello friends,

with the following code

import std.stdio;
import std.array;

auto file71 = File(argv[2], "r");

string[][] buffer;
foreach (line; file71.byLines) {
     buffer ~= split(line, "\t");
}

I am trying to cut the lines from the file with tab as delimiter 
to pre-fetch the content of a file before further processing.

Each split() call gives correct string[] values in and of itself.
But when I try to read buffer, after the loop, I got corrupted 
data, like this:

[ ["-", "_Unit226", "constructor", 
"sub_00BE896C\t1\t?:?\t\t//con", "t", "uc...

Obviously the concatenation is doing no good, since there are 
tabs in the values...

What am I missing here ? Is it that split() allocated memory that 
gets overwritten in the loop and the ~= just copies the subarrays 
not copying the subsubarrays ? How to overcome this ?

Thank you very much,
Ludovit


More information about the Digitalmars-d-learn mailing list