I am using StreamWriter to write to a file. When I use a text with 10-50 word text, it works properly. However when i call the function again (it exceeds the 50 words) it crashes. Why is this happening? Any suggestions?
Here is the codes:
StreamWriter file = new StreamWriter("text6.txt");
file.Close();
int count = 0;
string temp = "";
string temp2 = "";
for (Match m = Regex.Match(str, qmatch2); m.Success; m = m.NextMatch())
{
temp = m.Value;
temp2 = Regex.Replace(temp, qmatch2, " . ");
str = Regex.Replace(str, temp, temp2);
}
if (temp.Contains(".") == false)
{
file = File.AppendText("text6.txt");
file.WriteLine(" " + temp);
count++;
file.Close();
}
Try this: