Number of Vowels in a string [Resolved]

Posted by Murugavelmsc under C# on 2/27/2013 | Points: 10 | Views : 6253 | Status : [Member] | Replies : 11
Hi Experts,

How to fine Number of Vowels in a string?

Thanks,
Murugavel S

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/



Responses

Posted by: Jayakumars on: 2/27/2013 [Member] [MVP] Bronze | Points: 50

Up
0
Down

Resolved
hi

check this code

protected void Button1_Click(object sender, EventArgs e)
{
//AEIOU
string st = "JESUS";
string st2 = "";
int total = 0;
string Concats = "";
for (int i = 0; i <= st.Length - 1; i++)
{
st2 = st[i].ToString();
if (st2 == "A" || st2 == "E" || st2 == "I" || st2 == "O" || st2 == "U")
{
total = total + 1;
Concats = Concats + st2;
}
}
Response.Write("Real String : " + st + " Strings : " + Concats + " Counts : " + total);
}

Mark as Answer if its helpful to you

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja_89 on: 2/28/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hai Techie

char[] vowel = new char [] {'a', 'e', 'i', 'o', 'u' };
string line = Console.ReadLine().ToLower ();
char letter;
int vowels = 0,i;
for (i = 0; i < line.Length; i++)
{
letter = line[i];
letter = line of i [with in square brackets]
if (vowel.Contains(letter))
vowels++;


}
Console.WriteLine("No of vowels is:{0}", vowels);
Console.ReadLine();

Regards

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Somu475 on: 2/27/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Murugavelmsc,

You can write a method like below and call that method by sending your input string as parameter.

private static int findVowel(string str)

{
int count = 0;
for (int i = 0; i < str.Length - 1; i++)
{
switch (str[i])
{
case 'a': count++;
break;
case 'A': count++;
break;
case 'e': count++;
break;
case 'E': count++;
break;
case 'i': count++;
break;
case 'I': count++;
break;
case 'o': count++;
break;
case 'O': count++;
break;
case 'u': count++;
break;
case 'U': count++;
break;
}
}
return count;
}


Mark as answer if it helps you..

-Somu

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/27/2013 [Member] Starter | Points: 25

Up
0
Down
HI Jayakumar,

st2 = st.ToString(); has been replaced as
st2 = st[i].ToString();

Thanks,
Murugavel S


Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 2/28/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down

ofcourse

if u have any query for this code ask me.


Mark as Answer if its helpful to you

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
other than this it works fine

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 2/28/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

murugavel

donot forgot mark as useful for this answer.

Mark as Answer if its helpful to you

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
ofcourse

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja_89 on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hai Techie


char[] vowel = new char [] {'a', 'e', 'i', 'o', 'u' };
string line = Console.ReadLine().ToLower ();
char letter;
int vowels = 0,i;
for (i = 0; i < line.Length; i++)
{
letter = line[i];
if (vowel.Contains(letter))
vowels++;


}

Console.WriteLine("No of vowels is:{0}", vowels);
Console.ReadLine();

Happy Coding


Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Raja,

It is not working....

letter = line; //Error 1 Cannot implicitly convert type 'string' to 'char'

Thanks,
Murugavel S


Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/28/2013 [Member] Starter | Points: 25

Up
0
Down
thanks a lot...............

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response