我正在尝试解析 C# 中的文本文件。我想提取“Rows_affected”值大于 500 的行号。
这是我的文本文件的示例..
Query_time: 0.000268 Lock_time: 0.000097 Rows_sent: 1 Rows_examined: 38 Rows_affected: 0 Rows_read: 1
Query_time: 0.000308 Lock_time: 0.000115 Rows_sent: 0 Rows_examined: 38 Rows_affected: 500 Rows_read: 0
Query_time: 0.000169 Lock_time: 0.000057 Rows_sent: 0 Rows_examined: 38 Rows_affected: 300 Rows_read: 0
Query_time: 0.000296 Lock_time: 0.000111 Rows_sent: 0 Rows_examined: 38 Rows_affected: 50 Rows_read: 0
Query_time: 0.000238 Lock_time: 0.000081 Rows_sent: 0 Rows_examined: 38 Rows_affected: 1 Rows_read: 0
Query_time: 0.000318 Lock_time: 0.000110 Rows_sent: 1 Rows_examined: 38 Rows_affected: 600 Rows_read: 1
这是我的代码...
int lineNumb = 0;
using (System.IO.StreamReader file = new System.IO.StreamReader(openFileDialog1.FileName)) {
while ((line = file.ReadLine()) != null) {
lineNumb++;
if (line.StartsWith("# Query_time:")) {
int value = Convert.ToInt32(line.Split(':')[5].Split(' ')[1]);
if (value > 500) {
listBox1.Items.Add(lineNumb.ToString() + " > " + value.ToString());
}
int lineNumb = 0;
using (System.IO.StreamReader file = new System.IO.StreamReader(openFileDialog1.FileName))
{
while ((line = file.ReadLine()) != null)
{
lineNumb++;
if (line.StartsWith("# Query_time:"))
{
int value = Convert.ToInt32(line.Split(':')[5].Split(' ')[1]);
if (value > 500)
{
listBox1.Items.Add(lineNumb.ToString() + " > " + value.ToString());
}
}
}