tuples from text file

Steven Schveighoffer schveiguy at yahoo.com
Wed Dec 20 01:21:01 UTC 2017


On 12/19/17 7:47 PM, codephantom wrote:
> 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?

Well, you need to know at compile time the types you are expecting. Then 
you just parse them out.

You can't decide tuples at runtime.

-Steve


More information about the Digitalmars-d-learn mailing list