C#Linq非元音

C#Linq非元音,c#,linq,C#,Linq,从给定的字符串 (即) 如何提取非元音单词?类似于: var nonVowelWords = str.Split(' ').Where(x => Regex.Match(x, @"[aeiou]") == null); 这应该起作用: var nonVowels = str.Split(' ').Where(x => x.Intersect("aeiou").Count() == 0); Contains要求您传递一个字符。使用Enumerable.Contains也只能用于单个

从给定的字符串

(即)

如何提取非元音单词?

类似于:

var nonVowelWords = str.Split(' ').Where(x => Regex.Match(x, @"[aeiou]") == null);
这应该起作用:

var nonVowels = str.Split(' ').Where(x => x.Intersect("aeiou").Count() == 0);
Contains要求您传递一个字符。使用Enumerable.Contains也只能用于单个字符,因此需要多次调用。Intersect应该处理这个案子。

大家现在来吧。就是它所在的位置。:)

string str = "dry sky one two try";
var nonVowels = str.ToCharArray()
    .Where(x => !new [] {'a', 'e', 'i', 'o', 'u'}.Contains(x));
//如果这是公共的,那么设置单个元素的人很容易受到攻击。
私有静态只读字符[]元音=“aeiou”.ToCharArray();
//C#3
var nonpowerworks=str.Split(“”).Where(word=>word.IndexOfAny(元音)<0);
//C#2
列表词=新列表(str.Split(“”));
words.RemoveAll(委托(字符串词){return word.IndexOfAny(元音)>=0;});

非常感谢。假设我使用C#2.0,我该如何处理它?同样的方法,但是调用扩展方法作为静态方法,并使用匿名委托来代替lambda:
委托(字符串x){返回可枚举的.Count(可枚举的.Intersect(x,“aeiou”)==0;}
应该是
str.Split
,不
ToCharArray
string str = "dry sky one two try";
var nonVowels = str.ToCharArray()
    .Where(x => !new [] {'a', 'e', 'i', 'o', 'u'}.Contains(x));
// if this is public, it's vulnerable to people setting individual elements.
private static readonly char[] Vowels = "aeiou".ToCharArray();

// C# 3
var nonVowelWorks = str.Split(' ').Where(word => word.IndexOfAny(Vowels) < 0);

// C# 2
List<string> words = new List<string>(str.Split(' '));
words.RemoveAll(delegate(string word) { return word.IndexOfAny(Vowels) >= 0; });