Function interp

Interpolated string (ie, variable expansion).

string interp(string str)();

Any D expression can be placed inside ${ and }. Everything between the curly braces will be evaluated inside your current scope, and passed as a parameter (or parameters) to std.conv.text.

The curly braces do NOT nest, so variable expansion will end at the first closing brace. If the closing brace is missing, an Exception will be thrown at compile-time.


// Output: The number 21 doubled is 42!
int num = 21;
writeln( mixin(interp!"The number ${num} doubled is ${num * 2}!") );

// Output: Empty braces output nothing.
writeln( mixin(interp!"Empty ${}braces ${}output nothing.") );

// Output: Multiple params: John Doe.
auto first = "John", last = "Doe";
writeln( mixin(interp!`Multiple params: ${first, " ", last}.`) );