How can I directly reffer literal element itself inside [] slice?

Marcone marcone at email.com
Mon Jan 11 22:58:23 UTC 2021


On Monday, 11 January 2021 at 21:01:57 UTC, Paul Backus wrote:
> On Monday, 11 January 2021 at 15:45:51 UTC, Marcone wrote:
>>
>> I can reffer length of literal string using $.
>>
>> "Hello World"[0..$]
>>
>> But I want make like it witout use variable name.
>>
>> "Hello World"[0..?.indexOf("o")]
>
> The exact syntax you want is impossible. The closest you can 
> get is to use an `enum` constant, which is essentially a named 
> literal:
>
> enum hello = "Hello World";
> writeln(hello[0 .. hello.countUntil("o")]); // "Hell"

I don't want use enum, I want use literal.


More information about the Digitalmars-d-learn mailing list