4
Reply

Replace Path in Text File C#

SIVA

SIVA

Jul 17 2015 2:07 AM
607
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)