public static int indexOfIgnoreCase ( String s , String substr , int startIndex , int endIndex ) { if ( startIndex < 0 ) { startIndex = 0 ; } int srclen = s . length ( ) ; if ( endIndex > srclen ) { endIndex = srclen ; } int sublen = substr . length ( ) ; if ( sublen == 0 ) { return startIndex > srclen ? srclen : startIndex ; } substr = substr . toLowerCase ( ) ; int total = endIndex - sublen + 1 ; char c = substr . charAt ( 0 ) ; mainloop : for ( int i = startIndex ; i < total ; i ++ ) { if ( Character . toLowerCase ( s . charAt ( i ) ) != c ) { continue ; } int j = 1 ; int k = i + 1 ; while ( j < sublen ) { char source = Character . toLowerCase ( s . charAt ( k ) ) ; if ( substr . charAt ( j ) != source ) { continue mainloop ; } j ++ ; k ++ ; } return i ; } return - 1 ; }
Finds first index of a substring in the given source string and range with ignored case .