4
Answers

Replace Path in Text File C#

SIVA

SIVA

9y
7.2k
1
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)