tags:

views:

223

answers:

4
string webPath = folderPath.Replace("\", "/");

Hi, I'm trying to replace the above but struggling. Will I need an apply an escape sequence to /. If so anyone know what it is in c#. Any help/hints much appreciated.

+5  A: 
string webPath = folderPath.Replace(@"\", "/");
Mitch Wheat
+10  A: 
string webPath = folderPath.Replace(@"\", "/");
shahkalpesh
+10  A: 
string webPath = folderPath.Replace("\\", "/");

... would also work.

Steve
+1  A: 

As others have said, you have to escape the \ but not the /, and you can avoid the escaping entirely using a verbatim string literal - a string literal prefixed by @ which allows multi-line string constants, and doesn't escape any characters other than " which needs to be doubled.

See my (somewhat old, but still accurate in this case) C# FAQ for a full list of escape sequences.

Jon Skeet
Downvoters: comments are helpful when downvoting. Explain why the answer is unhelpful. (I figured the other answers had explained the most immediate question, and that I'd just help the questioner to not need to ask in similar situations.)
Jon Skeet
cant imagine what the problem might be, it's exactly what i was looking for...
sweeney