class FunWithScheduling
{
static void Main()
{
StringBuilder newFile = new StringBuilder();
string temp = "";
string[] file = File.ReadAllLines(Scheduler.txt");
foreach (string line in file)
{
if (line.Contains("Subhadra"))
{
temp = line.Replace("Subhadra", "Thangam");
newFile.Append(temp + "\r\n");
continue;
}
newFile.Append(line + "\r\n");
}
File.WriteAllText("Scheduler.txt", newFile.ToString());
}
}
答案 0 :(得分:3)
您错过了以下行中的开头报价:
string[] file = File.ReadAllLines(Scheduler.txt");
因此,编译器正在读取之后的所有结尾引号作为字符串常量的开头。
为了解决这个问题,你需要将上面一行更改为下面的行,其中有一个开头的引号: -
string[] file = File.ReadAllLines("Scheduler.txt");