String Interpolation
jmh530
john.michael.hall at gmail.com
Fri Oct 27 12:49:24 UTC 2023
On Friday, 27 October 2023 at 09:47:15 UTC, Arafel wrote:
> [snip]
> Good luck explaining these subtleties to new / casual users.
We can add an error message when assigning to a string that tells
the user to call `.text` or whatever if they want the string.
I tried to think of when I just want a string after doing
interpolation (as opposed to writing immediately somehow) and
struggled a bit. I think it would be usually in a string
concatenation situation. So I asked Adam on his PR whether this
works
```d
auto x = 1;
auto y = 2;
auto s1 = i"The value of x is $x,";
auto s2 = i"and the value of y is $y.";
writeln(i"$s1 $s2");
```
and he says it does.
Something like `writeln(s1, " ", s2)` would also work.
More information about the Digitalmars-d
mailing list