How can I directly reffer literal element itself inside [] slice?
Paul Backus
snarwin at gmail.com
Mon Jan 11 21:01:57 UTC 2021
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"
More information about the Digitalmars-d-learn
mailing list