I have a string containing a server file path ($\MyPath\Quotas\ExactPath\MyFile.txt) and a local file system path (C:\MyLocalPath\Quotas\ExactPath). I want to replace the server file path with the local system path.
I currently have an exact replace:
String fPath = @"$\MyPath\Quotas\ExactPath\MyFile.txt";
String sPath = @"$\MyPath\Quotas\ExactPath\";
String lPath = @"C:\MyLocalPath\Quotas\ExactPath\";
String newPath = fPath.Replace(sPath, lPath);
But I want this to be a case-insensitive replace, so that it would replace $\MyPath\quotas\Exactpath\ with lPath as well.
I came across the use of Regular Expressions like the following:
var regex = new Regex( sPath, RegexOptions.IgnoreCase );
var newFPath = regex.Replace( fPath, lPath );
But how do I handle the special characters ($,\,/,:) so that it is not interpreted as a regular expression special character?
You can use Regex.Escape: