我有一个如下所示的程序,它正在解析一个 .csv 文件。IT 打开 StreamReader 并搜索关键字。我正在尝试让用户更改 txt 文件中的搜索参数而不是实际程序。关于如何让所有这些代码一起工作的任何建议都会非常有帮助。
using System;
using System.Data;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Mail;
namespace ConsoleApplication5
{
class Test
{
public static void Main()
{
var dic = File.ReadAllLines("test.txt")
.Select(l => l.Split(new[] { '=' }))
.ToDictionary(s => s[0].Trim(), s => s[1].Trim());
try
{
using (StreamReader sr = new StreamReader("c:/temp/ESMDLOG.csv"))
{
string currentLine;
// currentLine will be null when the StreamReader reaches the end of file
while ((currentLine = sr.ReadLine()) != null)
{
// Search, case insensitive, if the currentLine contains the searched keyword
if (currentLine.IndexOf("I/RPTGEN", StringComparison.CurrentCultureIgnoreCase) >= 0)
{
Console.WriteLine(currentLine);
//Console.ReadLine();
}
}
}
}
catch (Exception e)
{
Console.WriteLine("The File could not be read:");
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
}