Below you will find a very brute force way or measuring this:
int CountChars(char cChar, string sString, bool bCaseSensitive)
{
if (!bCaseSensitive)
{
cChar = Char.ToLower(cChar);
sString = sString.ToLower();
}
if (sString.IndexOf(cChar) == -1)
{
return 0;
}
else
{
int i;
int iCount = 0;
int iStart = sString.IndexOf(cChar);
for (i = iStart; iStart == sString.Length - 1; iStart++)
{
if (sString[i] == cChar)
{
iCount++;
}
}
return iCount;
}
}
You can chose to tell the function to check for case sensitivity or not.
EDIT Once I posted this code, I saw it was the C# forum. I have fixed the code.