I want to count a particular character as shown in the code
but it seems to be case-sensitive. Can anyone tell me what is wrong with the code? Thanks
class ClassTwo
{
public static void Main(String[] args)
{
ClassTwo ct = new ClassTwo();
Console.WriteLine(ct.GetCountLetters("canada", 'A'));
}
int GetCountLetters(string text, char c)
{
int count = 0;
text = text.ToLowerInvariant();
char[] chars = text.ToCharArray(); // 'c' 'a' 'n' 'a' 'd' 'a'
for (int i = 0; i < chars.Length; i++)
{
if (chars[i] == c)
{
count++;
}
}
return count;
}
}