T... args!
    Salih Dincer 
    salihdb at hotmail.com
       
    Fri Apr 29 16:10:52 UTC 2022
    
    
  
On Friday, 29 April 2022 at 12:57:15 UTC, Steven Schveighoffer 
wrote:
> There is no string interpolation in D. You can use a function 
> such as `std.conv.text` to produce a string given interleaving 
> strings and items. Or you can use `std.format.format` to make 
> it happen.
I see, think it can be done with mixin:
```d
template prn(alias args)
{
   string prn()
   {
     string result = "write(";
     foreach(s; args.split("|"))
     {
       result ~= format("%s,", s);
     }
     return result ~ ");";
   }
}
void main()
{
   int data = 456;
   char enter = '\n';
   mixin(prn!q{
     enter| 123 | " str " |  data |
     enter|    __TIME__   | enter }
   );
   mixin(
     prn!q{"This value of " |41| " is prime."}
   );
}
```
If there was some convenience on the compiler side, we could 
integrate it into D.
SDB at 79
    
    
More information about the Digitalmars-d-learn
mailing list