如何自动逃避路径

我有一个像c:\user\test\test.jpg这样的路径字符串,如何才能使它成为c:\\user\\test\\test.jpg

 string s = s.Replace(@"\", @"\\"); 

试试这个:

 string path = @"c:\user\test\test.jpg"; 

如果在代码中使用字符串文字,则只需要转义。 为什么你还需要自动转义。 你可以在不需要转义的文字之前使用@。