抓住List <string>的一部分

DaF*_*lex 30 c# linq

我有一个List,看起来像这样:

some headline content
a subheadline containing the keyword 
1 2015-05-05 some data
2 2015-05-05 some data
3 2015-05-05 some data
some content
a subheadline containing another keyword 
useless stuff
Run Code Online (Sandbox Code Playgroud)

所以现在我想抓住"关键字"和"另一个关键字"之间的所有内容.也许我应该找到"关键字"和"另一个关键字"的索引并使用.GetRange(),但有没有更优雅的方法来实现这一点,例如LINQ

Ese*_*ser 58

你可以使用SkipWhileTakeWhile

var newList = list.SkipWhile(line => !line.Contains("keyword"))
                  .Skip(1)
                  .TakeWhile(line => !line.Contains("another keyword"))
                  .ToList();
Run Code Online (Sandbox Code Playgroud)