我有一个包含一些信息的文本文件。我想通过跳过几行来阅读它。例如,假设我的行中有 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
你猜对了吗?我如何使用 C# 实现此目的?我也想得到我稍后跳过的台词。有什么想法吗?
最佳答案
您可以使用包含索引的 LINQ Where
的重载,并使用 %
过滤每隔一行:
var everyOtherLine = System.IO.File.ReadAllLines("path")
.Where((s, i) => i % 2 == 0);
关于c# - 如何通过传递某些行来读取文本文件行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11163627/