Subscribe to danzar's Blog        RSS Feed
-----

Mega Project ideal list. - "Text" section / Count Vowels

Icon Leave Comment
I am taking the input from a text box and lower all the text. Then I convert the string to a char array. Then loop though the array and test for each vowel. Adding to the vowel in the loop if it was found.
Once the loop is over it test all the vowels for >0. Then displays the results in the output label.


 private void vowelcounterCount_bt_Click(object sender, RoutedEventArgs e)
        {
            string inputstring = vowelcounterInput_tb.Text.ToLower();
            int a = 0, e_ = 0,i = 0,o = 0, u = 0;
            char[] ch_input = inputstring.ToArray();
            foreach (char item in ch_input)
            {
                switch(item)
                {
                    case 'a':
                        a++;
                        break;
                    case 'e':
                        e_++;
                        break;
                    case 'i':
                        i++;
                        break;
                    case 'o':
                        o++;
                        break;
                    case 'u':
                        u++;
                        break;
                    default:
                        break;      

                }
            }
            StringBuilder output = new StringBuilder();
            if (a > 0) { output.Append(" a's =" + a); }
            if (e_ > 0) { output.Append(" e's =" + e_); }
            if (i > 0) { output.Append(" i's =" + i); }
            if (o > 0) { output.Append(" o's =" + o); }
            if (u > 0) { output.Append(" u's =" + u); }
            output.Append(" Total vowels=" + (a + e_ + i + o + u).ToString());
            vowelcounterOutput_lb.Content = output;
        }

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

October 2017

S M T W T F S
1234567
891011121314
151617181920 21
22232425262728
293031    

Tags

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)