我有以下代码。在我打开文件时对文本文件进行更改时,我看不到任何更改,实际上文本文件的文本已被删除。
private void btnGo_Click(object sender, EventArgs e)
{
string content;
string newword = "Tanu";
string oldword = "Sunrise";
System.IO.StreamReader file =
new System.IO.StreamReader(txtFilePath.Text);
while ((content = file.ReadLine()) != null)
{
if (content == "Project name = Sunrise ")
{
string newtxt = Regex.Replace(content, oldword, newword);
content = content.Replace(content, newtxt);
}
// counter++;
}
file.Close();
using (StreamWriter writer = new StreamWriter(txtFilePath.Text))
{
writer.Write(content);
writer.Close();