Wednesday, September 9, 2009

C# Word Counter

I don write code for long time. I wrote this program just to count an essay ;) So not a very big deal actually.
What I have practiced here :
  • Openfiledialog : How to open and select a file.
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "File to read";
fDialog.Filter = "txt files|*.txt";
fDialog.InitialDirectory = @"C:\Documents and Settings\roni\Desktop\Temp";

if (fDialog.ShowDialog() == DialogResult.OK)
//MessageBox.Show(fDialog.FileName.ToString());
  • Reading a file:
StringBuilder newFile = new StringBuilder();
string filestring = File.ReadAllText(@"C:\p_keydump.txt");
filestring = filestring.Replace("\r\n", ",");
  • Count the number of words is the file.
countedWords = strText.Split(' ').Length;

No comments:

Post a Comment