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

user1234 user1234 at 12.de
Fri Aug 13 21:14:29 UTC 2021


On Friday, 13 August 2021 at 21:05:22 UTC, Marcone wrote:
> How to extend the string class to return this inside the square 
> bracket the same way opDollar $ returns the length of the 
> string? Thank you.
>
>     import std;
>
>     void main(){
>     	writeln("Hello World!"[0..this.indexOf("o")]);
>     }

this does not exist (and see few reason for) but algo + ufcs 
allows this easily, e.g

```
"Hello World!".findSplit("o")[0].writeln;
```

bonus: both can throw bound error



More information about the Digitalmars-d-learn mailing list