SteamReaderに問題があります。文字列が存在することがわかっていても、私のStreamReaderはファイル内の特定の文字列一致を見つけられません。これを示す最善の方法はイメージを通してです。どのように動作するかを理解することができます。後でコードを提供します: StreamReaderがファイル内に文字列を見つけられません
Imageは、文字列がファイル内にあるかどうかを確認するコードを表示します。開いているテキスト文書は、チェックされたファイルです。これは、新しいフォーム(このフォーム)が情報を入力した後に作成されるときに、変数として渡されます。フォームボタンは、図のようにコードを実行するボタンです。文字列が見つからない場合は、メッセージボックスが表示されます。
ファイルがそれを拾うていないだけで、文字列をcontiansが、見ることができるように:/
私は、これは非常に単純なものである疑いがあるが、私は目の新鮮なペアを必要とします。
private void btnGetActivities_Click(object sender, EventArgs e)
{
if (File.Exists(sVenueName.ToString() + ".txt"))
{
using (StreamReader RetrieveEvents = new StreamReader(sVenueName.ToString() + ".txt")) //Create a new file with the name of the username variable
{
string EventString;
string EventType;
string EventPeopleAttending;
string line = RetrieveEvents.ReadLine(); //Declare string variable to hold each line in the file
while (RetrieveEvents.Peek() != -1)
{
if (line.Contains("Event Name:")) //When this line is found,
{
EventString = line.Remove(0, 12); //Remove the characters from the line and store it in a variable
lstDisplayActivities.Items.Add(line);
line.Skip(1).Take(2);
EventType = line.Remove(0, 12);
lstDisplayActivities.Items.Add(line);
line.Skip(2).Take(3);
EventPeopleAttending = line.Remove(0, 18);
lstDisplayActivities.Items.Add(line);
}
else
{
MessageBox.Show("No Files were found");
}
}
}
}
}
まあ、あなたはメッセージボックスを受け取っているのですが、すべての行に 'Event Name:'があります。 – CNuts
この行はどうなると思いますか? _line.Skip(1).Take(2); _ – Steve
何行あるかによって、そのメッセージを4/5回取得する必要があります。おそらくそれを 'while()'の終わりまで保持しておいてください – vipersassassin