On Friday, 13 August 2021 at 21:14:29 UTC, user1234 wrote:
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
My example was just an example. I don't want this solution. I
want to have the power to handle the string inside the square
brackets.