How to extend the string class to return this inside the square bracket?

Marcone marcone at email.com
Sat Aug 14 15:48:12 UTC 2021


On Saturday, 14 August 2021 at 08:24:41 UTC, user1234 wrote:
> 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.

Very Good!!! This pipe!() is just what I am looking for. Thank 
you very much!!!!


More information about the Digitalmars-d-learn mailing list