String interpolation

mw mingwu at gmail.com
Thu May 21 18:25:18 UTC 2020


On Thursday, 21 May 2020 at 06:57:28 UTC, mw wrote:
> On Thursday, 21 May 2020 at 01:13:27 UTC, Paul Backus wrote:
>> On Wednesday, 20 May 2020 at 23:41:15 UTC, mw wrote:
>>> Can we do string interpolation in D now?
>>
>> There's an implementation in the dub package "scriptlike":
>>
>> https://code.dlang.org/packages/scriptlike#string-interpolation
>
> Thank you! very nice:
>
> // Output: The number 21 doubled is 42!
> int num = 21;
> writeln( mixin(interp!"The number ${num} doubled is ${num * 
> 2}!") );
>
> Is there any way to make it shorter? e.g.
>
> writeln( s!"The number ${num} doubled is ${num * 2}!" );
>
> i.e how to write this 's'?

And for debug print, I like the output be:

The number num=21 doubled is num * 2=42!

i.e print out the string of the original expression, like the 
stringy operator in C’s macro #var




More information about the Digitalmars-d-learn mailing list