java indexof nth occurrence

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

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
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