Count the number of occurrences of character c in a string.
/**
* This software is provided as IS by Antilia-Soft SL.
* Copyright 2006-2007.
*/
//package com.antilia.common.util;
publicclass StringUtils {
/**
* counts the number of occurrences of character c in a string.
*
* @param str
* @param c
* @return int
*/
publicstaticint countChar(String str, char c) {
int start = -1;
int count = 0;
while (true) {
if ((start = str.indexOf(c, start + 1)) == -1)
return (count);
count++;
}
}
}