nested csv into tsv
bioinfornatics
bioinfornatics at fedoraproject.org
Sun Mar 18 07:45:41 PDT 2012
dear, i have this data:
________________________________
data1 data2 data3a;data3b;data3c
cata1 cata2 cata3a;cata3b;cata3c
tata1 tata2 tata3a;tata3b;tata3c
________________________________
field are sepaated by tab but third field contain data separeted by semi
colon
I have try:
________________________________
import std.csv;
import std.string;
import std.stdio;
struct Data{
public:
string field1;
string field2;
@property void field3( string field ){
_field3 = field.split(";");
}
@property string[] field3( ){
return _field3;
}
private:
string[] _field3;
}
void main(){
Data[] result;
File f = File( "data.csv", "r" );
foreach( char[] line; f.byLine() ){
result ~= csvReader!Data(line, '\t').front;
}
}
________________________________
This build fine but do not works at runtime
________________________________
$ ./test_csv
std.csv.CSVException@/usr/include/d/std/csv.d(1047): Can't parse string:
"[" is missing
std.conv.ConvException@/usr/include/d/std/conv.d(2714): Can't parse
string: "[" is missing
std.conv.ConvException@/usr/include/d/std/conv.d(1597): Unexpected 'd'
when converting from type string to type string[]
________________________________
More information about the Digitalmars-d-learn
mailing list