Get benefited from interview Q/A and Online Test section. Subscribe to this blog to get updates directly in your mail box.
Best View in Google Crome, Mozilla firefox or IE 7 or above

Wednesday, January 12, 2011

Find number of words in a text file in C# Dotnet

The below code can be used to count the number of words in a text file.

using System;
using System.IO;

namespace ConsoleApplication1
{
class CountWords
{
public string content { get; set; }


 internal int wordsInFile(string P)
 {
   return File.ReadAllText(P).Split(' ').Length;
 }
}

class Program
{
 static void Main(string[] args)
 {
 CountWords c = new CountWords();
 int numWords = c.wordsInFile(@"C:\test_data.txt");
 Console.WriteLine(numWords);
 Console.ReadLine();
 }
}
}

Text and Speech Project in C# Dotnet

No comments:

Post a Comment

  © Blogger templates Shiny by Ourblogtemplates.com 2008

Back to TOP