This is the solution I sent on the 20th, in response to Sushma's email
to me :

---
private void FindVowels(string input)
{
  char[] vowels = new Char[] { 'a', 'e', 'i', 'o', 'u' };
  int pos = 0;
  bool found = false;
  do
  {
    pos = input.IndexOfAny(vowels, pos);
    if(pos > -1)
    {
      pos += 1;
      Console.WriteLine("Vowel found at position: {0}", pos.ToString
());
      if(!found)
        found = true;
    }
  } while(pos > -1);

  if(found == false)
    Console.WriteLine("No Vowels found in the supplied string.");
}
---

Comments/improvements are appreciated.

On Dec 25, 10:54 am, "sushma sushma" <[email protected]> wrote:
> Here you go.
>
> 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)|(ch == ch3)|(ch == ch4)|(ch == ch5)|(ch ==
> ch6))
>                      j++;
>               }
>             Console.WriteLine(j);
>         }
>     }
>
> }
>
> On Wed, Dec 24, 2008 at 7:25 PM, Brandon Betances <[email protected]>wrote:
>
>
>
>
>
>
>
> > DAMN. Endless for-else loops and an undeclared variable. sweet.
>
> > On Wed, Dec 24, 2008 at 6:30 PM, DotnetBeginner <[email protected]>
> > wrote:
>
> > > 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.
>
> --
> Thanks,
>
> Sushma
>
> Email: [email protected]
>
> Mobile: (571) 438 1206- Hide quoted text -
>
> - Show quoted text -

Reply via email to