Interpolated strings
Jonas Drewsen via Digitalmars-d
digitalmars-d at puremagic.com
Wed Apr 19 05:10:33 PDT 2017
On Wednesday, 19 April 2017 at 12:03:47 UTC, Stefan Koch wrote:
> On Wednesday, 19 April 2017 at 11:59:51 UTC, Jonas Drewsen
> wrote:
>
>> What about supporting an optional prefix inside the {} like:
>>
>> int year = 2017;
>> format($"The date is {%04d year}");
>>
>> so if there is a % immediately following the { then the chars
>> until next whitespace is format specifier. You can of course
>> leave out the format specifier and it will default to %s.
> I really don't see how string interpolation is better then
> ` "The date is " ~ format("%04d", year)); `
As mentioned before it is only because it is such a common
pattern that it justifies the change. Seems like many other
languages reached that conclusion as well.
Also take a look at a more realistic example with some more
formatting and it will be more obvious (at least to me it is :) )
"The date is " ~ format("%04d", year)) ~ " and " ~ user ~ " just
logged into " ~ here;
$"The date is {%04d year} and {user} just logged into {here}"
More information about the Digitalmars-d
mailing list