Using LINQ remove vowels from string

c#, lambda

Solution

Although Yaakov's reg-ex solution is much better in terms of elegancy and efficiency, you can use `Where` for the sake of learning:

string[] strArray = new string[] { "cello", "guitar", "violin" };
var vowels = new HashSet<char>("aeiou"); // or: { 'a', 'e', 'i', 'o', 'u' };

var vNovowels2 = from vitem in strArray
                 select new string(vitem.Where(c => !vowels.Contains(c)).ToArray());

foreach (var item in vNovowels2)
{
    Console.WriteLine(item);
}

Problem

I want remove vowels from string array i did it with foreach loops but now want to perform it with using LINQ or Lambda expression I have tried the following code LINQ ``` string[] strArray = new string[] { "cello", "guitar", "violin"}; string[] vowels = new string[] { "a", "e", "i", "o", "u" }; var vNovowels = from vitem in strArray from vowel in vowels where vitem.Contains(vowel) select vitem.Replace(vowel, ""); foreach (var item in vNovowels) { Console.WriteLine(item); } ``` But i am not getting what is expected . Output i am getting with above query is :- ``` cllo cell guitr gutar gitar voln vilin ``` Desired output : ``` cll gtr vln ```

Original source

Related problems