我有一个应用程序,它从文本文件中读取信息,然后对其进行分类并将其放入数据库中。对于一个类别,我需要检查当前行后面的行,并查找特定的关键词?
当streamreader已经打开当前行时,如何读取此行?
我正在使用VS2010上的C#。
编辑:
下面的所有代码都在while(!sReader.EndOfStream)循环中。
此外,打开的.log文件可能会达到50MB之类的大小...!这就是为什么我不太喜欢阅读所有行并跟踪的原因!
当streamreader已经打开当前行时,如何读取此行?
我正在使用VS2010上的C#。
编辑:
下面的所有代码都在while(!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.....
此外,打开的.log文件可能会达到50MB之类的大小...!这就是为什么我不太喜欢阅读所有行并跟踪的原因!
StreamReader.ReadLine()
吗? - rossipedia