Thursday, 8 August 2013

Trying to replace a string in the text file but not working

Trying to replace a string in the text file but not working

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());
}
}

No comments:

Post a Comment