C#.NET Program 5

Output:




































Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Question_5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int vowels = 0;
        int digits = 0;
        int consonants = 0;
        int spaces = 0;
        int specialChar = 0;

        private void check()
        {
            string s = textBox1.Text;
            for (int i = 0; i < textBox1.Text.Length; i++)
            {
                if (s[i] >= '0' && s[i] <= '9')
                    digits++;
                else if (s[i] == 'a' || s[i] == 'A' || s[i] == 'I' || s[i] == 'e' || s[i] == 'E' || s[i] == 'i' || s[i] == 'I' || s[i] == 'o' || s[i] == 'O' || s[i] == 'u' || s[i] == 'U')
                    vowels++;
                else if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z'))
                    consonants++;
                else if (s[i] == ' ')
                    spaces++;
                else
                    specialChar++;
            }

            MessageBox.Show("Total Digits : " + digits + "\n" + "Total Vowals :" +  vowels +"\n" + "Total Consonants : " + consonants + "\n" + "Total Spaces : " + spaces + "\n" + "Total SpecialCharacter : " + specialChar); 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            check();
        }

        
    }
}




No comments:

Post a Comment