我是C#的新手,我已经开始使用StreamReader
。我试图一次读取一行文件,并在与“I/RPTGEN”等特定关键字匹配时输出该行。如何一次读取一行CSV文件并解析出关键字
到目前为止,我想出了如何将整个文件读入一个字符串,但是我一直无法一次只读一行。
我的代码到目前为止是这样的。
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication5
{
class Test
{
public static void Main()
{
try
{
using (StreamReader sr = new StreamReader("c:/temp/ESMDLOG.csv"))
{
String line = sr.ReadToEnd();
Console.WriteLine(line);
Console.ReadLine();
}
}
catch (Exception e)
{
Console.WriteLine("The File could not be read:");
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
}
}
此外,这里是文件中的一行的示例。
咨询2 /2013分之27上午12时00分44秒,I/RPTGEN(cadinterface),I/RPTGEN失败 - 错误500 - 内部服务器错误 - 返回报告请求(查看日志的URL) 。
@Tosi他的问题是在标题为“如何读取CSV文件一行的时间和解析出关键字”。不要这么苛刻。 – 2013-03-21 23:40:04