The back slash is a special character to the C# compiler. So, when you want
to use it in a string, you must place an escape character in front of it.
The escape character is also a back slash. (alternatively, you can place the
'@' character in front of a string to indicate to the compiler that the
following is a literal string, with no special characters in it.
Consequently the compiler treats or sees
"\\"
and
@"\"
as the exact same string.
So your original replace operation , s = s.Replace("\\", @"\"); , replaces
a single back slash with a single back slash. This is a nonsensical
operation.
If you want to replace two back slashes with a single back slash, either of
these should work:
s = s.Replace("\\\\", "\\");
or
s = s.Replace(@"\\", @"\");
Note that this "escape character" stuff is all for the compiler. So the
comiler will, for example, translate "\\" to be "\" in the output assembly.
This is why you see "\\" in Visual Studio, when your application shows "\"
-HTH
-S
"Gabriel" <no****@nospam.comwrote in message
news:Or****************@TK2MSFTNGP06.phx.gbl...
>
>You forgot @ at first string.
s.Replace(@"\\", @"\");
Hello Alex,
It's strange that. In the debugger I see \\ but when I display the path in
the application caption I see \
Thanks,