私は、テキストファイルから情報を読み取り、それらを分類してデータベースに格納するアプリケーションを持っています。 1つのカテゴリについては、現在の行の直後にある行をチェックして特定のキーワードを探す必要がありますか?ファイルの次の行を一度だけ読み取る
どうすればこの行を読むことができますか?ストリームリーダーが現在開いている回線を既に持っている場合に発生します。
私は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.....
である。また、開かれた.logファイルは行くかもしれません50メガバイトまで!...!だから私は本当にすべての行を読んでトラックを保つことを好まないのです!
StreamReaderには「行がありません」がありません。 –
'StreamReader.ReadLine()'を呼び出すことはできませんか? – rossipedia
@ブライアン:ちょうどその行に移動するだろうか?私は次の繰り返しのためにその行をもう一度読む必要があります。 – techmanc