Reputation: 551
Say I have a string s
like this:
s = "... *begin* - some-code-here - *end* ..."
i: ^
and an index i
pointing to a position between "*begin*"
and "*end*"
, e.g., to the 'e'
of "some"
.
To get the index of the (next) occurrence of "*end"*
, I could use
s.indexOf("*end*", i)
Is there a similar way to get the index of the next "*begin*"
to the left?
Upvotes: 2
Views: 801
Reputation: 79
I want this answer to add as comment to wero's answer but due to low reputation I am unable to do so.
I think it should be like
s = s.substring(0, i);
s.indexOf("*begin");
Upvotes: 0