如何用String.Replace()将"\\"替换为"\"

Nic*_*rin 0 c# string replace

我想,以取代"\\""\"(两到只有一个).我正在使用:

string myPath = Path.GetFullPath(fileName);    
string correctPath = myPath.Replace(@"\\", @"\");
Run Code Online (Sandbox Code Playgroud)

但没有任何反应,correctPath中的字符串继续 "\\"

DGi*_*bbs 10

您可能在调试器中暂停时查看字符串.将值打印到控制台窗口,没关系.

string myPath = @"hello\\world";
string correctPath = myPath.Replace(@"\\", @"\");
Console.Write(correctPath);
Console.Read();
Run Code Online (Sandbox Code Playgroud)