Hi Guys,
The easy way for beginners to count vowels in a string is
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the string");
string chr = Console.ReadLine().ToLower();
char ch2 = 'a';
char ch3 = 'e';
char ch4 = 'i';
char ch5 = 'o';
char ch6 = 'u';
int j = 0;
foreach (char ch in chr)
{
if (ch == ch2)
j++;
else
if (ch == ch3)
j++;
else
if (ch == ch4)
j++;
else
if (ch == ch5)
j++;
else
if (ch == ch6)
j++;
}
Console.WriteLine(j);
}
}
}
On Dec 18, 1:49 pm, Cerebrus <[email protected]> wrote:
> I would do it the following way :
>
> 1. Create a char array comprising of the vowel letters.
> 2. Run a While loop searching within the string from position 0 and
> looping each time you find a vowel, this time starting with the
> position at which find was successful.
>
> Happy Homework-ing !!
>
> On Dec 18, 8:56 am, DotnetBeginner <[email protected]> wrote:
>
> > I am trying to return num ofvowelspresent in a string using c#. I am
> > not getting that. Can any body have any ideas
>
> > Appreciated.