count number of words in a text file
Hello guys,please I need a program that will count the number of words in a text file.
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.
VulpesPosted Mar 4, 2015, 5:46 AM
Manish Kumar ChoudharyPosted Mar 4, 2015, 3:40 AM
public string ReadTextFile(string filename)
{
StreamReader re = File.OpenText(filename);
string result = "";
string input = "";
try
{
while ((input = re.ReadLine()) != null)
{
Thread.Sleep(5000);
for (int i = 0; i < input.Length; i++)
{
result += input[i];
Thread.Sleep(2500);
}
}
}
catch (Exception ex)
{
// do something here.
}
finally
{
if (re != null)
{
Thread.Sleep(2500);
re.close;
}
re = null;
}
}
private int CountWords(string filename, string text)
{
int wordCount = 0;
try
{
for (int i = 0; i < text.Length; i++)
{
if (text[i] == ' ' || text[i] == '\i')
{
Thread.Sleep(500);
wordCount++;
if (wordCount > 1)
{
Thread.Sleep(500);
ReadTextFile(filename);
}
}
}
}
catch (Exception ex)
{
// do something here
}
return wordCount;
}