tuples from text file
codephantom
me at noyb.com
Wed Dec 20 00:47:16 UTC 2017
so I have a text file containing 3 lines(e.g):
5, "hello", 4.3
"hello", 4.3
"hello", "world", 1, 2, 3, 5.5
Now I want to create tuples from each line.
However, (using line 1 as example), I get:
Tuple!string("5, \"hello\", 4.3")
but I really want:
Tuple!(int, string, double)(5, "hello", 4.3)
I know why - because a line is a string.
But anyone got an idea on how to extract the string into separate
elements that can be correctly 'tuple'd" according to the type of
each element?
// -------
module test;
import std.stdio : writeln;
import std.typecons;
import std.string;
import std.file : readText;
void main()
{
string myFile= "tuples.txt"; // contains 3 lines as per
examples above
auto lineArr = readText(myFile).splitLines();
writeln( tuple(lineArr[0]) ); // doesn't give me the tuple I
want.
}
//-----------
More information about the Digitalmars-d-learn
mailing list