In this Blog I am trying to remove the
duplicates characters. For example the string aabbccdefefe would become
abcdef And in addition to that In this program i am counting vowels and
consonants appeared in a string.
using System;
namespace removing_duplicate_character
{
class Program
{
static void Main(string[] args)
{
int j,i,vowel=0,con=0,pos=1;
string str;
char[] a = new char[30];
Console.WriteLine("Enter
string");
str = Console.ReadLine();
for (i = 0; i < str.Length; i++)
{
a[i] = str[i];
}
for (i = 1; i < str.Length; i++)
{
for (j = 0; j < i; j++)
{
if (a[i] == a[j])
break;
}
if (j == i)
{
a[pos] = a[i];
pos++;
}
}
Console.WriteLine("Output
After Removing Duplicate Character");
for (i = 0; i < pos; i++)
{
Console.Write(a[i]);
}
for (i = 0; i < pos; i++)
{
if (a[i] == 'a' || a[i]
== 'e' || a[i] == 'i' || a[i] == 'o' || a[i] == 'u' || a[i] == 'A' ||
a[i] == 'E' || a[i] == 'I' || a[i] == 'O' || a[i] == 'U')
{
vowel++;
}
else
{
con++;
}
}
Console.WriteLine("\nno of
vowels are "+vowel);
Console.WriteLine("no of
consonant are "+con);
Console.ReadLine();
}
}
}