Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java indexof nth occurrence

public static int ordinalIndexOf(String str, String substr, int n) {
    int pos = str.indexOf(substr);
    while (--n > 0 && pos != -1)
        pos = str.indexOf(substr, pos + 1);
    return pos;
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #java #indexof #nth #occurrence
ADD COMMENT
Topic
Name
4+9 =