Is there a simple way of getting the penultimate delimited substring of a string?
String original = "/1/6/P_55/T_140";
In this example, the resulting substring would be "P_55/T_140"
I would like to find the index of forward slash at the beginning of this substring (/)
I know String.lastIndexOf() calling twice would help. But looking for a cleaner approach which is generic. Perhaps to any N.
Calling
String.lastIndexOf(int,int)in a loop is going to be quite efficient, and arguably pretty clean:This can be easily turned into a helper function taking
str,'/'andn, and returningout.