Better string mixins
SashaGreat
s at g.com
Fri Dec 28 12:51:33 UTC 2018
On Friday, 28 December 2018 at 12:43:28 UTC, SashaGreat wrote:
> On Friday, 28 December 2018 at 12:34:27 UTC, rikki cattermole
> wrote:
>> No need.
>>
>> import std.stdio;
>> import std.format;
>>
>> void main() {
>> int x;
>> mixin("x = %d;".format(8));
>> writeln(x);
>> }
>
> Yes, but for the second case it would be ugly...
>
> mixin("x = {0}; y = {1}", x, y);
>
> S.
By the way, thinking more about it, in C# (My main language), in
could easily create a extension for this like:
public static Format(string this, object[] args){
// Loop through all the {x} replacing with arg[x]
}
Then
"x = {0}".Format(1);
"x = {0}; y = {0}".Format(10, 20);
Is this possible with D?
S.
}
More information about the Digitalmars-d
mailing list