I came across a forum post where the person wanted to count all the
- small letters in a string
- capital letters in a string
- vowels in a string
This reminded me of my lab assignments from programming 101 days.Here is the basic code
Console.WriteLine("Please enter a string");
string myString = Console.ReadLine();
byte[] ASCIIBytes = Encoding.ASCII.GetBytes(myString);
int iSmallCount = 0;
int iCapsCount = 0;
int iVowelCount = 0;
foreach (byte ASCII in ASCIIBytes)
{
if (ASCII >= 65 && ASCII <= 90)
iCapsCount++;
else if (ASCII >= 97 && ASCII <= 122)
iSmallCount++;
switch (ASCII)
{
case 65:
case 69:
case 73:
case 79:
case 85:
case 97:
case 101:
case 105:
case 111:
case 117:
iVowelCount++;
break;
}
}
Console.WriteLine("Number of small letters in the entered string: " + iSmallCount);
Console.WriteLine("Number of cap letters in the entered string: " + iCapsCount);
Console.WriteLine("Number of vowel letters in the entered string: " + iVowelCount);
No comments:
Post a Comment