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

  • Home
  • SEARCH
  • 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 6023147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:57:43+00:00 2026-05-23T03:57:43+00:00

I have a textbox where the user enters a random string. I want to

  • 0

I have a textbox where the user enters a random string. I want to count the number of vowels(A,E,I,O,U) in the string and show th results in the labelcontrol.

protected void Button1_Click(object sender, EventArgs e)
    {
        string EnterString;
        EnterString = TextBox1.Text;
        char ch1 = 'a';
        char ch2 = 'e';
        char ch3 = 'i';
        char ch4 = 'o';
        char ch5 = 'u';

        int counta = 0;
        int counte = 0;
        int counti = 0;
        int counto = 0;
        int countu = 0;
        char ch6 = 'A';
        char ch7 = 'E';
        char ch8 = 'I';
        char ch9 = 'O';
        char ch10 = 'U';

        int countA = 0;
        int countE = 0;
        int countI = 0;
        int countO = 0;
        int countU = 0;

        //const string vowels = "aeiou";
        /* return value.Count(chr => vowels.Contains(char.ToLower(chr)));
         return Value.Count()*/
        int j = counta + counte + counti + counto + countu + countA + countE + countI + countO + countU;

        foreach (char v in EnterString)
        {
            if (v == ch1) { counta++; j++; }

            else if (v == ch2) { counte++; j++; }

            else if (v == ch3) { counti++; j++; }

            else if (v == ch4) { counto++; j++; }

            else if (v == ch5) { countu++; j++; }
        }
        foreach (char v in EnterString)
        {
            if (v == ch6) { countA++; j++; }

            else if (v == ch7) { countE++; j++; }

            else if (v == ch8) { countI++; j++; }

            else if (v == ch9) { countO++; j++; }

            else if (v == ch10) { countU++; j++; }
        }

        Label1.Text = j.ToString();
    }
  • 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-05-23T03:57:44+00:00Added an answer on May 23, 2026 at 3:57 am

    You have this in your code:

    const string vowels = "aeiou";
    return value.Count(chr => vowels.Contains(char.ToLower(chr)));
    

    That works, at least if your culture is US. So no idea why you commented it out in favor of the current monstrosity.

    On a Turkish locale it will fail because the lower case of I is not i but ı (undotted). So if you define vowels as aeiouAEIOU you should use ToLowerInvariant.

    But if you want to include other vowels (like Ä) I have no idea how to do that except by listing all the characters.

    Full implementation:

    int CountVowels(string value)
    {
        const string vowels = "aeiou";
        return value.Count(chr => vowels.Contains(char.ToLowerInvariant(chr)));
    }
    

    Looks like you got the good code part from:
    Counting vowels using switch

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user that want to be able to select a textbox and
I have a user control with a ComboBox and a TextBox. Everything is working
I have a custom user control with a textbox on it and I'd like
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have an ASP.Net web user control that contains a TextBox and a calendar
I have a user control that is pretty basic. It contains several TextBox controls,
I have a DropDownList and a TextBox on a Page. When the user chooses
I want to have a text box that the user can type in that
I have an ASP.NET user control that contains a text box control and a
In my application I have TextBox in a FormView bound to a LinqDataSource like

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.