JunkieHF

Count Number of Vowels in String (C# Source Code)

Dec 19th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Vowel_Counter
  12. {
  13.     public partial class frmVowelCounter : Form
  14.     {
  15.         public frmVowelCounter()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         private void btnCount_Click(object sender, EventArgs b)
  21.         {
  22.             string text = txtText.Text;
  23.             int my_count = 0;
  24.  
  25.             foreach (char ch_vowel in text)
  26.             {
  27.                 switch (ch_vowel)
  28.                 {
  29.                     case 'a':
  30.                     case 'A':
  31.                         my_count++;
  32.                         break;
  33.                     case 'e':
  34.                     case 'E':
  35.                         my_count++;
  36.                         break;
  37.                     case 'i':
  38.                     case 'I':
  39.                         my_count++;
  40.                         break;
  41.                     case 'o':
  42.                     case 'O':
  43.                         my_count++;
  44.                         break;
  45.                     case 'u':
  46.                     case 'U':
  47.                         my_count++;
  48.                         break;
  49.                     default:
  50.                         break;
  51.                 }
  52.             }
  53.            
  54.             if (text == "")
  55.             {
  56.                 MessageBox.Show("There are 0 vowels. Please enter some text.");
  57.             }
  58.  
  59.             else
  60.             {
  61.                 MessageBox.Show("The number of vowels in " + text + " is " + my_count);  
  62.             }
  63.         }
  64.  
  65.         private void btnExit_Click(object sender, EventArgs e)
  66.         {
  67.             this.Close();
  68.         }
  69.     }
  70. }
Add Comment
Please, Sign In to add comment