November 29, 2017 Storing Formatted Array Value | ||||
|---|---|---|---|---|
| ||||
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
| ||||
November 29, 2017 Re: Storing Formatted Array Value | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Vino | 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); } | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply