Linq:在字符串中搜索所有多个空格

Ara*_*and 2 c# linq string

我有一个字符串,我想找到所有多个空格出现的位置.我正在写一个标点符号检查器.我想使用并行linq来分离这个操作,但在此期间我只是寻找linq方法让我开始.

spe*_*der 6

继Fredou的回答之后,正则表达式会做得很好.Regex.Matches返回一个MatchCollection,它是一个(弱类型)Enumerable.使用Cast <T>扩展后,这可以是Linq-ified :

Regex.Matches(input,@" {2,}").Cast<Match>().Select(m=>new{m.Index,m.Length})
Run Code Online (Sandbox Code Playgroud)