Lambda表达式中使用正则表达式

某语句如果不用正则表达式:

string[] names = { "Tom", "Dick", "Harry", "Mary", "Jay" };

IEnumerable<string> query = names.Select(n => n.Replace("a", "").Replace("e", "").Replace("i", "").Replace("o", "").Replace("u", ""))

用正则表达式可简化为:

IEnumerable<string> query =names.select(n => Regex.Replace(n, "[aeiou]", ""));

posted on 2017-09-10 11:56  mol1995  阅读(975)  评论(0编辑  收藏  举报

导航