SIVA

SIVA

  • NA
  • 742
  • 699.5k

Replace Path in Text File C#

Jul 17 2015 2:07 AM
Hi,

I am trying to replace path in given text file. I am using regular expression for that.
filePath = txtFilePath.Text;
oldPath = txtOld.Text;
newPath = txtNew.Text;

string output = File.ReadAllText(filePath);
output = Regex.Replace(output, oldValue, newValue, RegexOptions.IgnoreCase);
File.WriteAllText(filePath, output);
I have tried oldPath.Replace(@"\\", @"\") also but now use.
It throwing an exception like unrecognised escape sequence. Please let me know the solutions.

Answers (4)