public static int search ( String str , String keyw ) { int strLen = str . length ( ) ; int keywLen = keyw . length ( ) ; int pos = 0 ; int cnt = 0 ; if ( keywLen == 0 ) { return 0 ; } while ( ( pos = str . indexOf ( keyw , pos ) ) != - 1 ) { pos += keywLen ; cnt ++ ; if ( pos >= strLen ) { break ; } } return cnt ; }
Returns the number of times the specified string was found in the target string or 0 if there is no specified string .