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
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Pankaj Kumar ChoudharyRank #80 · 24.4K reputationPosted Mar 12, 2015, 8:00 PM EDT
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();
Khargesh RajputRank #616 · 3.9K reputationPosted Mar 12, 2015, 8:02 PM EDT