Prune double slahes

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I prune double slashes from a string?
<appSettings>
<add key="pdfroot" value="p:\E-Switch Secure\PDF_dwgs\"/>
</appSettings>
string path = ConfigurationManager.AppSettings["pdfroot"];
path = path.Replace("\\\\", "\\"); // Doesn't work
path = path.Replace(@"\\", @"\"); // Doesn't work
 
But... unless I am missing something, it doesn't contain any double
slashes... is this just a debugger issue? It displays strings in the escaped
form, so \ appears \\. But it is still \.

Marc
 
To Marc's point, are the slashes even there at all? Isn't the compiler trying
to escape out the characters before it?

Try:
<appSettings>
<add key="pdfroot" value="p:\\E-Switch Secure\\PDF_dwgs\\"/>
</appSettings>
string path = ConfigurationManager.AppSettings["pdfroot"];

Tossing that to a Textbox would display:

"p:\E-Switch Secure\PDF_dwgs\"

--
Reproduced, simplistically, with:

string pathname = "p:\\E-Switch Secure\\PDF_dwgs\\";
output.Text = pathname;

value from output.text in presentation:
p:\E-Switch Secure\PDF_dwgs\
 
Hi David,

Xml doesn't have to be escaped for C# because it's not compiled, so "\\" isn't
required. One backslash should be just fine.

This is most likely a misunderstanding due to the debugger's representation of
the string, as others have pointed out.

--
Dave Sexton

David Longnecker said:
To Marc's point, are the slashes even there at all? Isn't the compiler
trying to escape out the characters before it?

Try:
<appSettings>
<add key="pdfroot" value="p:\\E-Switch Secure\\PDF_dwgs\\"/>
</appSettings>
string path = ConfigurationManager.AppSettings["pdfroot"];

Tossing that to a Textbox would display:

"p:\E-Switch Secure\PDF_dwgs\"

--
Reproduced, simplistically, with:

string pathname = "p:\\E-Switch Secure\\PDF_dwgs\\";
output.Text = pathname;

value from output.text in presentation: p:\E-Switch Secure\PDF_dwgs\

---

-dl

---
David Longnecker
Web Developer
http://blog.tiredstudent.com
But... unless I am missing something, it doesn't contain any double
slashes... is this just a debugger issue? It displays strings in the
escaped form, so \ appears \\. But it is still \.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top