C# 尝试替换文本文件中的字符串但不起作用

C# 尝试替换文本文件中的字符串但不起作用,c#,C#,您缺少以下行中的起始报价: class FunWithScheduling { static void Main() { StringBuilder newFile = new StringBuilder(); string temp = ""; string[] file = File.ReadAllLines(Scheduler.txt");

您缺少以下行中的起始报价:

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());
            }
         }
因此,编译器正在读取作为字符串常量开头的结束引号之后的所有内容

为了解决这一问题,您需要将上面的行更改为下面的行,其中包含起始报价:-

string[] file = File.ReadAllLines(Scheduler.txt");

怎么不起作用了?你能再努力一点吗?比如,请更详细地描述您的问题,而不是“但不工作”?CS1010不断换行。在each@user2665618:您缺少第一个引号。@user2665618:-将字符串[]file=file.ReadAllLines(Scheduler.txt”);替换为我已回答的引号!!:)我真的不明白this@user2665618查看我的编辑-您的代码缺少一个
。为什么我投了反对票??:(
string[] file = File.ReadAllLines("Scheduler.txt");