Keep Vowels in String - CSharp System

CSharp examples for System:String Algorithm

Description

Keep Vowels in String

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;/*from w  ww  .  j  av a  2  s .  com*/

public class Main{
        public static string KeepVowels(string input)
        {
            string ret = "";
            string currentLetter;
            for (int i = 0; i < input.Length; i++)
            {
                currentLetter = input.Substring(i, 1);

                if (String.Compare(currentLetter, "a", true) == 0 ||
                    String.Compare(currentLetter, "e", true) == 0 ||
                    String.Compare(currentLetter, "i", true) == 0 ||
                    String.Compare(currentLetter, "o", true) == 0 ||
                    String.Compare(currentLetter, "u", true) == 0)
                {
                    //A vowel, add it
                    ret += currentLetter;
                }
            }
            return ret;
        }
}

Related Tutorials