Create an application with a textbox in which user can enter a sentence then displays
1) Number of vowels
2) Number of spaces
3) Number of digits
4) Number of special symbols
When user press “analysis” button.
Design:-
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 Text_Analyser
{
public partial class frmtextanalyser : Form
{
public frmtextanalyser()
{
InitializeComponent();
}
private void btnanalyser_Click(object sender, EventArgs e)
{
if (txtentertext.Text != "")
{
string s;
char ch;
int nspace=0, nvowels=0, ndigit=0, nspecialsymboll=0;
s = txtentertext.Text;
int length=Convert.ToInt32(s.Length);
txtsizeoftext.Text = Convert.ToString(length);
try
{
for (int i =0; i <=length-1; i++)
{
ch = Convert.ToChar(s.Substring(i, 1));
char c=char.ToUpper(ch);
if (char.IsDigit(ch) == true)
{
ndigit++;
}
else if (char.IsWhiteSpace(ch) == true)
{
nspace++;
}
else if (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
{
nvowels++;
}
else if(Char.IsSymbol(ch) == true)
{
nspecialsymboll++;
}
}
}
catch { }
txtnumberofdigit.Text = Convert.ToString(ndigit);
txtnumberofspace.Text = Convert.ToString(nspace);
txtnumberofvowels.Text = Convert.ToString(nvowels);
txtspecialsymboll.Text = Convert.ToString(nspecialsymboll);
}
}
private void btnreseat_Click(object sender, EventArgs e)
{
txtentertext.Text = "";
txtnumberofdigit.Text = "";
txtnumberofspace.Text = "";
txtnumberofvowels.Text = "";
txtsizeoftext.Text = "";
txtspecialsymboll.Text = "";
}
private void btnexit_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
No comments:
Post a Comment