@ Nonnegative public static int getOccurrenceCount ( @ Nullable final String sText , final char cSearch ) { int ret = 0 ; final int nTextLength = getLength ( sText ) ; if ( nTextLength >= 1 ) { int nLastIndex = 0 ; int nIndex ; do { // Start searching from the last result nIndex = getIndexOf ( sText , nLastIndex , cSearch ) ; if ( nIndex != STRING_NOT_FOUND ) { // Match found ++ ret ; // Identify the next starting position (relative index + number of // search strings) nLastIndex = nIndex + 1 ; } } while ( nIndex != STRING_NOT_FOUND ) ; } return ret ; }
Count the number of occurrences of cSearch within sText .