Checks to see if a string contains vowels - CSharp System

CSharp examples for System:String Contain

Description

Checks to see if a string contains vowels

Demo Code


using System.Text.RegularExpressions;
using System.Text;
using System.Globalization;
using System.Collections.Generic;
using System;//from w w  w . j a va  2s  .c o m

public class Main{
        //Checks to see if a string contains vowels
        //hello -> True
        //rmv -> False
        public static bool HasVowels(string input)
        {
            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 found
                    return true;
                }
            }

            return false;
        }
}

Related Tutorials