Loading...

Learn How To Read , Write & Displays Number Of Characters, Lines And Words In Text File...


C Sharp Program That Displays Number Of Characters, Lines And Words In Text File...

In this program we make a text file in memory and also use the filing concept in it. In this code you learn how to make a text file and how to read or write from a text file. May this will help you if you have any problem or query with this code let us know we will definitely help you and make it clear to you....

Source Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace ConsoleApplication8
{
    class textfile
    {
        int rslt_chrctr = 0;
        string file = File.ReadAllText(@"D:\aqib.txt");

        public textfile()
        {
            Console.WriteLine("\n{0}\n\n", file);
        }

        public void chracters_count()
        {
            foreach (char a in file)
            {
                if (a > ' ')
                {
                    rslt_chrctr++;
                }
            }

            Console.WriteLine("The Number Of Characters Are {0}\n", rslt_chrctr);
        }

        public void words_count()
        {
            int WordCount = file.Split(' ').Length;
            Console.WriteLine("The Number Of Words Are {0}\n", WordCount);

        }

        public void lines_count()
        {
            var lines = file.Split(new char[] { '\n' });
            var line = lines.Count();
            Console.WriteLine("The Number Of Lines Are {0}\n", line);

        }

        static void Main(string[] args)
        {
            textfile tf = new textfile();
            tf.chracters_count();
            tf.words_count();
            tf.lines_count();
        }
    }
}

OUTPUT





Hit Like Button if you understood, It helps a lot to keep us Motivated.

0 comments:

Post a Comment

Google+

 
TOP