Slice/Substr [0..?lastIndexOf(".")] How refer itself without create a variable?
Andrea Fontana
nospam at example.com
Thu Dec 5 14:32:00 UTC 2019
On Thursday, 5 December 2019 at 11:28:51 UTC, Marcone wrote:
> Simple example:
>
> writeln("Hi\nHow are
> you?\nGood".splitLines()[0][0..?lastIndexOf(r"\")]);
>
> How to refer to this string in lastIndexOf() without create a
> variable?
>
> Thank you.
One solution:
writeln(
"Hello\nHow are you?\nGood"
.splitLines()
.map!(x => x[0..x.lastIndexOf("o")])
);
But be careful: lastIndexOf could be < 0 if string is not found.
More information about the Digitalmars-d-learn
mailing list