Warning: fopen(/tmp/SghXTngBZPli-q0HgDR.tmp): failed to open stream: Disk quota exceeded in /home/executea/public_html/blog/wp-admin/includes/class-wp-filesystem-ftpext.php on line 139

Warning: unlink(/tmp/SghXTngBZPli-q0HgDR.tmp): No such file or directory in /home/executea/public_html/blog/wp-admin/includes/class-wp-filesystem-ftpext.php on line 142
Site Loader
Auckland, New Zealand
Using the below given code snippet, we can open a text file and read the number of given character occurs Here is the algorithm Here is the code snippet
private static void ReadNoOfSimilarChar(string word)
        {
            StreamReader reader = File.OpenText(@"c:\data.txt");
            int letterCount = 0;
            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();

                for (int i = 0; i < line.Length; i++)
                {
                    if (line.Substring(i, 1) == word)
                    {
                        letterCount++;
                    }
                }
            }

            Console.Write(letterCount);
            Console.Read();
        }
Thanks, Karthik KK

Post Author: Karthik kk

One Reply to “Count number of similar Characters of a text file using C#”

Leave a Reply

Your email address will not be published. Required fields are marked *