Hi,
I want to get a count of each english letter in a text file.The lower case and upper case letter should be taken as 1 letter(i.e A and a should be counted as 1 letter).This is my code but it takes capital A ans simple a as 2 letters. Can anyone help?

int[] c = new int[(int)char.MaxValue];
                string file = openFileDialog.FileName;
               
                    string s = File.ReadAllText(file);
                  
                    foreach (char t in s)
                    {
                        c[(int)t]++;
                    }
                    for (int i = 0; i < (int)char.MaxValue; i++)
                    {
                        if (c[i] > 0 &&
                            char.IsLetter((char)i))
                        {
                            Console.WriteLine("Letter: {0}  Frequency: {1}",
                                (char)i,
                                c[i]);
                        }

Line 1 : You don't have to cast char.MaxValue to an int.
Besides that you can index your string s directly., but before you do that use the ToUpper or ToLower methods of your string object.

Read here about OpenFileDialog

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.