In: Computer Science
The user enters some text into a textbox. It can contain any characters (letters, digits, spaces, punctuation marks, and there is no length limit). When a button Count is hit , display the number of upper-case letters in the inputted phrase. This must be done in visual studios using C#.
Program:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CountUpperCaseDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCount_Click(object sender, EventArgs e)
{
string inputText;
int count = 0;
//Storing TextBox(txtInput) value into the string
inputText = txtInput.Text;
//checking each every characters of the string to get the
count
for (int i = 0; i < inputText.Length; i++)
{
//checking the upper case letters
if (inputText[i] >= 'A' && inputText[i] <= 'Z')
{
count++;
}
}
//displaying the number of upper-case letters in the inputted
phrase
MessageBox.Show("The number of upper-case letters in the inputted
phrase: "+count);
}
}
}
Output: