count number of words in a text file
hello guys,please I need a program that will count number of words in a text file using GUI.Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Khargesh RajputPosted Mar 13, 2015, 12:02 AM
Pankaj Kumar ChoudharyPosted Mar 13, 2015, 12:00 AM
int count=0;
string line;
string[] stm;
char [] split = { ' ', ',' };
using (StreamReader Red = new StreamReader(@"C:\My_File.txt"))
{
while (Red.Peek() > -1)
{
line = Red.ReadLine();
stm = line.Split(split);
foreach (string str in stm)
{
if (str != "")
count++;
}
}
}
Console.WriteLine(count.ToString());
Console.ReadKey();