Wednesday, May 29, 2013

Find vowels character in a String

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

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


No comments:

Post a Comment

Kashmir 370 and 35A : The Wound of india

क्या है जम्मू-कश्मीर में लागू धारा 370,35A पूर्ण विवरण Know about 370 act in Jammu एक बार फिर से राजनीति गलियारे में धारा 370,35A को ल...