java indexof nth occurrence

Solutions on MaxInterview for java indexof nth occurrence by the best coders in the world

showing results for - "java indexof nth occurrence"
Nohan
04 Apr 2016
1public static int ordinalIndexOf(String str, String substr, int n) {
2    int pos = str.indexOf(substr);
3    while (--n > 0 && pos != -1)
4        pos = str.indexOf(substr, pos + 1);
5    return pos;
6}
7