String joining an array of structs or class instances implementing toString?

pineapple via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 11 04:44:15 PST 2016


It feels like there should be an out-of-the box way to do this 
but I haven't been able to find it? Help?

This is the thing that I want to do:

struct example{
     const string str;
     //this(string str){ this.str = str; }
     string toString(){
         return this.str;
     }
}

public void main(){
     import std.stdio;
     import std.string;
     example[] parts = [example("hello"), example("world")];
     writeln(std.string.join(parts, " "));
}



More information about the Digitalmars-d-learn mailing list