About string and int spliced together.

zoujiaqing zoujiaqing at gmail.com
Fri Jul 31 18:18:29 UTC 2020


On Friday, 31 July 2020 at 13:56:00 UTC, Steven Schveighoffer 
wrote:
> On 7/30/20 2:59 PM, zoujiaqing wrote:
>> On Thursday, 18 June 2020 at 09:13:53 UTC, Dennis wrote:
>>> On Thursday, 18 June 2020 at 09:00:42 UTC, zoujiaqing wrote:
>>>> Type should be automatically converted to string!
>>>
>>> While this could be made to work for floating point numbers, 
>>> it is ambiguous for integers since integers are often 
>>> implicitly convertible to characters:
>>>
>>> writeln("AB"~67); // prints "ABC", code unit 67 represents 'C'
>>>
>>> You might be interested in Adam's string interpolation DIP 
>>> though:
>>> https://github.com/dlang/DIPs/pull/186
>> 
>> 
>> It's still too complicated.
>> 
>> The simplest way:
>> 
>> int i = 99;
>> 
>> string a = "text " ~ i ~ "!";
>> 
>> writeln(a); // text 99!
>
> what's complicated about:
>
> string a = i"text $i!".idup;
>
> -Steve

Thanks Steve.

but about:

string a = i"text $i!".idup;

or:

string a = "text" ~ i ~ "!";

or:

string a = "text {$i}!";


I think the latter two are simpler ;)



Ref: https://www.php.net/manual/en/language.types.string.php


More information about the Digitalmars-d mailing list