Share via


C# String Replace using Slashes

Question

Wednesday, December 28, 2011 2:35 PM

using C#.net 2010

trying this but not working, trying to replace the single backslashes with double backslashes, does anyone know how to fix this?

I guess that double backslash "\" is the escape sequence for a single backslash, but I just tried "\\" for the param on the right  which I think should be 2 backslashes but that does not work either.

thx

MyFullPath =MyFullPath.Replace("\", "\\");

you know what I think I got it, should be:

MyFullPath =MyFullPath.Replace("\\", "\\\\");

All replies (3)

Wednesday, December 28, 2011 2:45 PM âś…Answered

Try this ..

MyFullPath =MyFullPath.Replace("\\", "\\\\");

Wednesday, December 28, 2011 3:05 PM

Try this ..

MyFullPath =MyFullPath.Replace("\\", "\\\\");

thanks, I figured it out too but give you the credit because its the same solution.


Tuesday, November 20, 2012 12:41 AM

Try this:

MyFullPath =MyFullPath.Replace(@"\", @"\\");

The @ symbol means escape sequences won't be processed, read more about c# @ here 

http://www.kowitz.net/archive/2007/03/06/the-c-string-literal