On Friday, 13 August 2021 at 23:23:55 UTC, Marcone wrote:

writeln("Hello World!"[x.indexOf("e")..x.indexOf("r")]);

indexOf()is just a simple example, not the goal. I want handle literal inside [] like it bellow, but in literal:

string x = "Hello World!";
writeln(x[x.indexOf("e")..x.indexOf("r")]);

You can use the `pipe` function to bind an arbitrary expression to a variable:

```d
import std.functional: pipe;
import std.algorithm: countUntil;
import std.stdio: writeln;

"Hello world!"
    .pipe!(s => s[s.countUntil('e') .. s.countUntil('r')])
    .writeln;
```

Reply via email to