Exemplo n.º 1
0
        private static string TranslateWord(string word)
        {
            //declare variables
            const string WAY       = "way";
            const string AY        = "ay";
            const string VOWEL     = "aeiou";
            string       modString = ""; // returned variable
            int          position  = 0;

            int  count     = 0;
            char letter    = word[0];
            bool hasVowels = true;

            position = VOWEL.IndexOf(letter);
            while (position == -1 && count <= word.Length)
            {
                if (position == -1 && count < word.Length)
                {
                    ++count;
                    letter    = word[count - 1];
                    position  = VOWEL.IndexOf(letter);
                    hasVowels = true;
                }
                else
                {
                    ++count;
                    hasVowels = false;
                }
            }
            letter   = word[0];
            position = VOWEL.IndexOf(letter);
            if (position != -1) //means it is a vowel
            {
                modString = word + WAY;
            }
            else if (hasVowels)
            {
                count = 0;
                while (position == -1 && count < word.Length)
                {
                    ++count;
                    letter   = word[count];
                    position = VOWEL.IndexOf(letter);
                }
                //create new string
                modString = word.Substring(count) + word.Substring(0, count) + AY;
            }
            else
            {
                count = 0;
                //create new string
                modString = word.Substring(count) + word.Substring(0, count) + AY;
            }

            return(modString);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            const string NAME    = "BARLAN 123456789";
            const string VOWEL   = "AEIOU";
            const string NUM     = "0123456789";
            const string SURNAME = "URIZARTORRICO";


            foreach (var surname in SURNAME)
            {
                if (VOWEL.IndexOf(surname) >= 0)
                {
                    Console.WriteLine("The letter " + surname + " is vowel");
                }
                else if (NUM.IndexOf(surname) >= 0)
                {
                    Console.WriteLine("The names of the persons not content numbers ");
                }
                else
                {
                    Console.WriteLine("The letter " + surname + " is a consonat");
                }
            }
            foreach (var name in NAME)
            {
                if (NUM.IndexOf(name) >= 0)
                {
                    Console.WriteLine(name + " People's name doesn't have  a number");
                }
                else if (NAME.IndexOf(name) >= 0)
                {
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("The letter " + name + " is a consonat");
                }
            }
        }