Storing Formatted Array Value
Petar
Petar
Wed Nov 29 07:27:02 UTC 2017
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);
}
More information about the Digitalmars-d-learn
mailing list