Revision 9597

View differences:

trunk/libraries/libIverUtiles/src/com/iver/utiles/StringUtilities.java
464 464
    		}
465 465
    		return( new String( buffer ) );
466 466
    	}
467

  
468
    /**
469
     * Returns the number of occurrences of a chain of characters in an String
470
     * 
471
     * @param str The string where find into
472
     * @param subStr The chain of characteres that we want to know how many times occurs
473
     * @param caseSensitive 'true' if has to do case sensitive for each seek or 'false' if not
474
     * 
475
     * @return An integer value >= 0
476
     * 
477
     * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
478
     */
479
    public static int numberOfOccurrencesOfSubStringInString(String str, String subStr, boolean caseSensitive) {
480
    	int aux = 0;
481
    	int numberOfOccurrences = 0;
482
    	
483
    	if (!caseSensitive) {
484
    		str = str.toLowerCase();
485
    		subStr = subStr.toLowerCase();
486
    	}
487
    	
488
    	while (((aux = str.indexOf(subStr, aux)) != -1)) {
489
    		aux = aux + subStr.length();
490
    		numberOfOccurrences++;
491
    	}
492
    	
493
    	return numberOfOccurrences;
494
    }
467 495
}

Also available in: Unified diff