Introduction
Some one ask a question to me, how to find all vowels from a string without repeating vowels ( means you can find out vowels from a string but if one is come out like 'E' from that string, then next time it is not included with the output.
Now I write a code for Find out vowels from a given string.
Example
Some one ask a question to me, how to find all vowels from a string without repeating vowels ( means you can find out vowels from a string but if one is come out like 'E' from that string, then next time it is not included with the output.
Now I write a code for Find out vowels from a given string.
Example
using
System;
class
Program
{
static
void
Main()
{
string
value1 = RemoveDuplicateChars("AERTJEIUO");
for
(int
i = 0; i <= value1.Length - 1; i++)
{
// code that checks the char is vowel or not
if
(65 == (int)value1[i]
|| 69 == (int)value1[i]
|| 73 == (int)value1[i]
|| 79 == (int)value1[i]
|| 85 == (int)value1[i])
{
Console.WriteLine(value1[i]);
}
}
Console.ReadKey();
}
// method for removing the duplicate characters
static
string
RemoveDuplicateChars(string
key)
{
string
val1 =
"";
string
result =
"";
foreach
(char
value
in
key)
{
if
(val1.IndexOf(value) == -1)
{
val1 += value;
result += value;
}
}
return
result;
}
}
Output
Output
No comments:
Post a Comment