www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Storing Formatted Array Value

reply Vino <vino.bheeman hotmail.com> writes:
Hi All,

Request your help, with the below code I am able to print the 
value of the array without brackects , but can some on help me on 
hot to store this output to a variable

Program:
import std.stdio;
import std.container;

void main()
{
    auto test = Array!string("Test1", "Test2");
    writefln("%(%s, %)",test[]); // output : "Test1", "Test2"

    // Similar like this
    auto res = `writefln("%(%s, %)",test[])`;
    writeln(res);
}

Output of res should look like : "Test1", "Test2" (Without [] 
brackets).


From,
Vino.B
Nov 28 2017
parent Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
On Wednesday, 29 November 2017 at 07:08:12 UTC, Vino wrote:
 Hi All,

 Request your help, with the below code I am able to print the 
 value of the array without brackects , but can some on help me 
 on hot to store this output to a variable

 Program:
 import std.stdio;
 import std.container;

 void main()
 {
    auto test = Array!string("Test1", "Test2");
    writefln("%(%s, %)",test[]); // output : "Test1", "Test2"

    // Similar like this
    auto res = `writefln("%(%s, %)",test[])`;
    writeln(res);
 }

 Output of res should look like : "Test1", "Test2" (Without [] 
 brackets).


 From,
 Vino.B
https://dlang.org/phobos/std_format is your friend: // https://run.dlang.io/is/sUkOX0 import std.container; import std.format; import std.stdio; void main() { auto test = Array!string("Test1", "Test2"); writefln("%(%s, %)",test[]); // Similar like this auto res = "%(%s, %)".format(test[]); writeln(res); auto res2 = "%-(%s, %)".format(test[]); writeln(res2); }
Nov 28 2017