Remove Vowels programming exercise.

The evil wizard wants to curse the nearby library, but his wand is broken. He offers to conquer the entire world and rule it, but only if you help him to:


Write a function that will read a string and return a new one, but without all the vowels.

"Hello World" => "Hll Wrld"
"This library is for losers. LOL!" => "Ths lbrr s fr lsrs LL!"

Scroll down for the solution.

using System;
using System.Linq;

public static string RemoveVowels(string str) 
{ return string.Concat(str.Where(ch => !"aeiouyAEIOUY".Contains(ch))); }

    public static string RemoveVowels(string str)
    {
    //Lets start a variable for the result
    //then lets go through each character and

        string r = "";
        foreach (var item in str)
        {

     //copy all of them but the vowels.
     //like 'a' or 'e' or 'i' or 'o' or .. well all of them!
            if (item == 'a' || item == 'e' || item == 'i' || item == 'o' 
                || item == 'u' || item == 'y' || item == 'A' || item == 'E'
                || item == 'I' || item == 'O' || item == 'U' || item == 'Y')
            {

            }
            else
            {
                r += item;
            }
        }
        return r;
    }

It is very interesting. You can solve the problems in your code with few very technical lines or a lot of more simple lines. Which is better ? Doesn’t matter for now !! Solve them in any way that you can for now. Just write code. A lot of it! And little by little your code will start to look more technical too. Yes, try to have somewhat good OOP, but don’t over do it. Just make some projects, and FINISH them at all cost!! This is very important. Learn how to finish your projects and this will teach you a lot, don’t even menschen to portfolio that they can make. If you are a student and make most of your homework packaged as a product, or mobile app, or a website, at the time will graduate you will have nice portfolio. You can imagine a 20 newly graduated student go for the same job offer and most of them don’t have anything to offer. Who will do better ?