I take the text from a text box and test if its empty. If its not, then I split the string into and array by splitting it at the open space. Then I loop all the array items counting them. Then pass the results to a message box.
Second part is it opens a word file. Looping though it counting the words and then displays the results in a message box.
Second part is it opens a word file. Looping though it counting the words and then displays the results in a message box.
private void countstringCount_bt_Click(object sender, RoutedEventArgs e)
{
if (countwordInput_tb.Text != "")
{
int counter = 0;
string[] split_words = countwordInput_tb.Text.Split(' ');
foreach (string word in split_words)
{counter++;}
MessageBox.Show("Word count =" + counter);
}
}
private void countwordFileCount_bt_Click(object sender, RoutedEventArgs e)
{
StreamReader streamReader = new StreamReader(@"C:\wordlist.txt");
string text = streamReader.ReadToEnd();
streamReader.Close();
int counter = 0;
char[] delimiter = new char[] {'\r','\n',' '};
string[] split_words = text.Split(delimiter);
foreach (string word in split_words)
{ counter++; }
MessageBox.Show("Word count =" + counter);
}
0 Comments On This Entry
Trackbacks for this entry [ Trackback URL ]
Tags
My Blog Links
Recent Entries
-
-
Mega Project ideal list. - "Text" section / Count Words in a Stringon Oct 04 2012 11:05 AM
-
-
-
Search My Blog
0 user(s) viewing
0 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)
Categories
|
|



Leave Comment










|