String Interpolation

Imperatorn johan_forsberg_86 at hotmail.com
Thu Oct 26 10:12:49 UTC 2023


On Thursday, 26 October 2023 at 09:42:27 UTC, Arafel wrote:
> On 26/10/23 3:47, Adam D Ruppe wrote:
>> [...]
>
> You are not mentioning this part:
>
>> [...]
>
> I would find it perfect if there were an option to define 
> arbitrary prefixes to strings (other than the ones already used 
> by the language), like `i"Hello, ${name}` or `sql"SELECT * FROM 
> ${table};"`. Notice how the string itself doesn't need any 
> marker in Java:
>
>> [...]
>
> It's needing both what I don't like and find confusing: `string 
> s = i"Hello, ${world}".format` (or `.text`).
>
> We can do like Java, and assume that as soon as a template 
> expression is found, it will be automatically considered an 
> interpolated string, so actually strings literals will be 
> interpolated by default, and only if there are no expressions 
> the result would be a `string`.

Yes, if D doesn't provide that. It would be the only language 
(created by man at least) that does not give the user a string if 
desired.


More information about the Digitalmars-d mailing list