aro*_*han 1 c# visual-studio-2010
我有一个文本文件,其中包含一些行的信息.我想通过传递一些线条来阅读它.例如,假设我的行数为1-10.当我正在阅读时,我想通过以下方式阅读它,
1 <- i wanna read this
2 <- Skip this
3 <- read this
4 <- Skip this
5 <- read this
6 <- Skip this
7 <- read this
8 <- Skip this
9 <- read this
10 <- Skip this
Run Code Online (Sandbox Code Playgroud)
你得到了正确的模式吗?我怎样才能用c#实现这个目标?而且我想得到我以后跳过的台词.有任何想法吗?
您可以使用Where包含索引的LINQ的重载,并用于%过滤每隔一行:
var everyOtherLine = System.IO.File.ReadAllLines("path")
.Where((s, i) => i % 2 == 0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1359 次 |
| 最近记录: |