How to extend the string class to return this inside the square bracket?
user1234
user1234 at 12.de
Sat Aug 14 08:24:41 UTC 2021
On Friday, 13 August 2021 at 23:33:05 UTC, Paul Backus wrote:
> 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;
> ```
nice, that's the best alternative.
More information about the Digitalmars-d-learn
mailing list