只读一次文件的下一行

tec*_*anc 3 .net c# file streamreader

我有一个应用程序从文本文件中读取信息,然后对它们进行分类并将它们放到数据库中.对于一个类别,我需要检查当前行之后的行并查找某个关键字?

我如何阅读这一行?这个应该在streamreader已经打开当前行时发生....

我在VS2010上使用c#.

编辑:

下面的所有代码都是一段时间(!sReader.EndOfStream)循环

 string line = sReader.ReadLine(); //Note: this is used way above and lots of things are done before we come to this loop

 for (int i = 0; i < filter_length; i++)
 {
       if (searchpattern_queries[i].IsMatch(line) == true)
       {
               logmessagtype = selected_queries[i];

               //*Here i need to add a if condition to check if the type is "RESTARTS" and i need to get the next line to do more classification. I need to get that line only to classify the current one. So, I'd want it to be open independently *

               hit = 1;
               if (logmessagtype == "AL-UNDEF")
               {
                   string alid = AlarmID_Search(line);
                   string query = "SELECT Severity from Alarms WHERE ALID like '" +alid +"'";
                   OleDbCommand cmdo = new OleDbCommand(query, conn);
                   OleDbDataReader reader;
                   reader = cmdo.ExecuteReader();
                   while (reader.Read())
                   {
                        if (reader.GetString(0).ToString() == null)
                        { }
                        else
                        {
                             string severity = reader.GetString(0).ToString();
                             if (severity == "1")
                                 //Keeps going on.....
Run Code Online (Sandbox Code Playgroud)

此外,打开的.log文件可能达到50 Mb类型......!这就是为什么我真的不喜欢阅读所有线路并保持跟踪!

Ric*_*key 5

这是在处理下一行已经可用时处理当前行的习语:

public void ProcessFile(string filename)
{
    string line = null;
    string nextLine = null;
    using (StreamReader reader = new StreamReader(filename))
    {
        line = reader.ReadLine();
        nextLine = reader.ReadLine();
        while (line != null)
        {
            // Process line (possibly using nextLine).

            line = nextLine;
            nextLine = reader.ReadLine();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这基本上是一个队列,其中最多有两个项目,或"一行预读".

编辑:简化.