Newbie: Error parsing csv file with very long lines
salvari via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Apr 23 03:40:13 PDT 2016
Hello all!
I'm trying to read a csv file (';' as separator) with very long
lines.
It seems to be really simple, I read the columns name with no
problem. But as soon as the program parses the first line of
data, the array containing the columns names seems to be
overwrited.
I'm using dmd: DMD64 D Compiler v2.071.0
My code:
import std.stdio;
import std.algorithm;
import std.array;
char[][] columns;
void main() {
LINE:foreach(line; stdin.byLine()){
if(line.startsWith("Interfaz")){
writeln("IN HERE");
columns = line.split(";");
writeln(columns); // Everything seems to be ok
continue;
} else{
auto linedata = line.split(";");
writefln("My line: %s", line); // Fine.
writefln("LineData: %s", linedata); // Fine. Line data is
ok
writefln("Columns: %s", columns); // Wrong!!! columsn
array
// contains garbage
data
// from linedata
}
}
}
More information about the Digitalmars-d-learn
mailing list