例如我有 string = “c:\windows\123.txt”;
请问怎样替换为“c:\\windows\\123.txt”???

解决方案 »

  1.   

    替换的原因是什么啊 ?可以直接这样用啊string = @“c:\windows\123.txt”;
      

  2.   

    s. Replace("\\", "\\\\");   @"c:\windows\123.txt" 
     
      

  3.   

    string = @"c:\windows\123.txt";
    Regex.Replace(str,@"\","\\\\")
      

  4.   

                string a=@"c:\windows\123.txt";
                string b = a.Replace("\\","\\\\");
                Console.WriteLine(a);
                Console.WriteLine(b);
      

  5.   

     string = “c:\windows\123.txt”;
    编译都无法通过
     string = @“c:\windows\123.txt”;
      

  6.   

    string str = @"c:\windows\123.txt";
    str = str.Replace("\\","\\\\");
    或者
    str = str.Replace(@"\",@"\\");
    或者
    str = str.Replace(@"\","\\\\");
    或者
    str = str.Replace("\\",@"\\");