Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8092681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:20:16+00:00 2026-06-05T20:20:16+00:00

I am teaching myself C# and one of the current chapters challenges asks me

  • 0

I am teaching myself C# and one of the current chapters challenges asks me to prompt the user for a string, write back the string, count the number of characters, the instances of the letter ‘e’ and finally the instances of all vowels. It gave a hint to use switch but I couldn’t figure out how to do it. I did get it to work by doing it manually, but I don’t think that’s the point. 🙂 How could I use a switch statement to reduce the number of typed lines?

Console.WriteLine("Please type a sentence and hit enter: ");

string myString = Console.ReadLine();

int letterCount = myString.Split('e').Length - 1;

Console.Clear();
Console.WriteLine("Thank you.  The sentence you entered was: \n\"{0}\"", myString);
Console.WriteLine("This sentence is {0} characters long.", myString.Length);
Console.WriteLine("It contains {0} instances of the letter \'e\'.", letterCount);

int vowelCount = 0;
int letterALower = myString.Split('a').Length - 1;
vowelCount += letterALower;

int letterELower = myString.Split('e').Length - 1;
vowelCount += letterELower;

int letterILower = myString.Split('i').Length - 1;
vowelCount += letterILower;

int letterOLower = myString.Split('o').Length - 1;
vowelCount += letterOLower;

int letterULower = myString.Split('u').Length - 1;
vowelCount += letterULower;

int letterAUpper = myString.Split('A').Length - 1;
vowelCount += letterAUpper;

int letterEUpper = myString.Split('E').Length - 1;
vowelCount += letterEUpper;

int letterIUpper = myString.Split('I').Length - 1;
vowelCount += letterIUpper;

int letterOUpper = myString.Split('O').Length - 1;
vowelCount += letterOUpper;

int letterUUpper = myString.Split('U').Length - 1;
vowelCount += letterUUpper;

Console.WriteLine("There are {0} vowels used.", vowelCount);
Console.ReadLine();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:20:17+00:00Added an answer on June 5, 2026 at 8:20 pm

    Here’s a simple solution:

    string str = Console.ReadLine();
    string low_str = str.ToLower();
    Console.Clear();
    Console.WriteLine("Thank you.  The sentence you entered was: \n\"{0}\"", str);
    Console.WriteLine("This sentence is {0} characters long.", str.Length);
    
    int vowelCount = 0;
    int eCount = 0;
    
    for (int i = 0; i < low_str.Length; i++)
    {
        switch(low_str[i])
        {
            case 'e': eCount ++; vowelCount++; break;
            case 'a': vowelCount++; break;
            case 'o': vowelCount++; break;
            case 'i': vowelCount++; break;
            case 'u': vowelCount++; break;
            case 'y': vowelCount++; break;
        }
    }
    
    Console.WriteLine("It contains {0} instances of the letter \'e\'.", eCount);
    Console.WriteLine("There are {0} vowels used.", vowelCount);
    Console.ReadLine();
    

    Notice that this could be done in an even fewer lines using this method (not the best way, but let’s not go too deep into the framework details 🙂 ):

    int eCount = low_str.split(new char[]{'e'}) - 1;
    int vowelCount = low_str.split(new char[]{'a','e','o','i','u','y'}) - 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am teaching myself Objective-C utilizing a number of resources, one of which is
Hoping someone can help. I am teaching myself C# and one of the challenges
There is something wrong with my code. I am teaching myself c# and one
I'm teaching myself programming and today's challenge is to write a program that can
I have recently been teaching myself Haskell, and one of my exercises was to
I'm still teaching myself how to bind and use observable collection. One problem that
I'm teaching myself c++ and eigen in one go, so maybe this is an
I'm teaching myself Python. I saw a java permutation generator from a string, and
I am currently teaching myself C++ using A C++ for Dummies All-In-One; second edition.
I'm teaching myself C with K&R and am stumped by one of the examples

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.