About string and int spliced together.
Stanislav Blinov
stanislav.blinov at gmail.com
Thu Jun 18 09:14:39 UTC 2020
On Thursday, 18 June 2020 at 09:00:42 UTC, zoujiaqing wrote:
> Now dlang string processing is complex, like this:
> ...
> Type should be automatically converted to string!
> ...
> Like java:
No, it shouldn't. `string` is not a class, it's simply an array
of immutable chars. To an array, you can only append an
implicitly convertible type, or another array.
You can use [1], [2], or, for this example's sake, [3]
import std.stdio;
import std.conv : text;
import std.format : format;
void main()
{
string name = "Brian";
uint age = 18;
string str = text("My name is ", name, " and my age is ",
age, ".");
writeln(str);
str = format("My name is %s and my age is %s.", name, age);
writeln(str);
writefln("My name is %s and my age is %s.", name, age);
}
[1] https://dlang.org/phobos/std_conv.html#text
[2] https://dlang.org/phobos/std_format.html#.format
[3] https://dlang.org/phobos/std_stdio.html#.writefln
More information about the Digitalmars-d
mailing list