Reputation: 3177
I am getting file path of the StreamWriter
string fullPath = ((FileStream) (writer.BaseStream)).Name
which gives me:
C:\\P4\\depot\\projects\\_Delegates.generated.cs
Is there chance to get/convert this path to
C:\P4\depot\projects\_Delegates.generated.cs
without \\
but only with \
in a path.
Thanks
Upvotes: 1
Views: 4637
Reputation: 2243
C:\\P4\\depot\\projects\\_Delegates.generated.cs
--That should be what the actual string literal is, because the extra backslashes are needed as escape sequences. So in other words, if you were going to define the path yourself by just making a string variable, you would type it in that form...
string fullpath = "C:\\P4\\depot\\projects\\_Delegates.generated.cs"
But, if you were to actually print out the value with Console.WriteLine(fullpath);
The value you would actually see printed out would be:
C:\\P4\\depot\\projects\\_Delegates.generated.cs
In other words, its basically already in the format you need.
Upvotes: 2
Reputation: 51
You can use the Regex Replace function from Regular Expression
using System.Text.RegularExpressions;
private string Inhalt1 = null;
StreamWriter file = new StreamWriter(WindowsPath);
Regex rgx= new Regex(@"\\s");
NewPath= rgx.Replace(file, "\"); // the new Path
Upvotes: 1
Reputation: 22794
Try this:
fullpath = fullpath.Replace(@"\\", @"\");
Basically, replace every double back-slash in the string with a single slash.
Upvotes: 2