c#多行过滤器

本文关键字:过滤器 | 更新日期: 2023-09-27 18:03:11

嘿,我需要一些帮助;我有包含

something.txt
4   10:06:29      0      0          0
2   10:06:30      0      0          0
9   10:06:31      0      0          0
4   10:06:32      0      0          0
7   10:06:31      0      0          0

格式类似于

然后我有一些代码

System.IO.StreamReader file = new System.IO.StreamReader(path);
var lines1 = File.ReadAllLines(path).First(s => s.StartsWith(tempvar));
listBox1.Items.Add(lines1);

我需要过滤(绘制)以数字4开头的多行(例如)我的代码为他在文件(.txt文件)中找到的第一行执行此操作,需要一些帮助来处理多行

c#多行过滤器

在Linq查询中将First替换为Where应该可以做到。

System.IO.StreamReader file = new System.IO.StreamReader(path);
var listBox1 = File.ReadAllLines(path).Where(s => s.StartsWith(tempvar)).ToList();