我有一个应用程序从文本文件中读取信息,然后对它们进行分类并将它们放到数据库中。对于一个类别,我需要检查当前行后面的行并查找某个关键字?只读一次文件的下一行
我该如何阅读这一行?这应该发生在streamreader有当前行已经打开....
我在VS2010上使用c#。
编辑:
所有下面的代码是在而循环
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.....
此外,被打开.log文件可能会去(sReader.EndOfStream!)高达50 Mb类型...!这就是为什么我不喜欢阅读所有的线和保持跟踪!
StreamReader没有“打开线路”。 –
你不能只是调用'StreamReader.ReadLine()'? – rossipedia
@Bryan:那会不会只是搬到那条线?我需要这条线再次读取下一个迭代.. – techmanc