Prune double slahes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arne Garvander

    #1

    Prune double slahes

    How can I prune double slashes from a string?
    <appSettings>
    <add key="pdfroot" value="p:\E-Switch Secure\PDF_dwgs \"/>
    </appSettings>
    string path = ConfigurationMa nager.AppSettin gs["pdfroot"];
    path = path.Replace("\ \\\", "\\"); // Doesn't work
    path = path.Replace(@" \\", @"\"); // Doesn't work
    --
    Arne Garvander
    (I program VB.Net for fun and C# to get paid.)
  • Marc Gravell

    #2
    Re: Prune double slahes

    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


    Comment

    • Hans Kesting

      #3
      Re: Prune double slahes

      How can I prune double slashes from a string?
      <appSettings>
      <add key="pdfroot" value="p:\E-Switch Secure\PDF_dwgs \"/>
      </appSettings>
      string path = ConfigurationMa nager.AppSettin gs["pdfroot"];
      path = path.Replace("\ \\\", "\\"); // Doesn't work
      path = path.Replace(@" \\", @"\"); // Doesn't work
      See:




      Hans Kesting


      Comment

      • David Longnecker

        #4
        Re: Prune double slahes

        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_dwg s\\"/>
        </appSettings>
        string path = ConfigurationMa nager.AppSettin gs["pdfroot"];

        Tossing that to a Textbox would display:

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

        --
        Reproduced, simplistically, with:

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

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

        ---

        -dl

        ---
        David Longnecker
        Web Developer

        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
        >

        Comment

        • Dave Sexton

          #5
          Re: Prune double slahes

          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 misunderstandin g due to the debugger's representation of
          the string, as others have pointed out.

          --
          Dave Sexton

          "David Longnecker" <dlongnecker@co mmunity.nospamw rote in message
          news:463c247d6e 78c8d1356dce8dc b@msnews.micros oft.com...
          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_dwg s\\"/>
          </appSettings>
          string path = ConfigurationMa nager.AppSettin gs["pdfroot"];
          >
          Tossing that to a Textbox would display:
          >
          "p:\E-Switch Secure\PDF_dwgs \"
          >
          --
          Reproduced, simplistically, with:
          >
          string pathname = "p:\\E-Switch Secure\\PDF_dwg s\\";
          output.Text = pathname;
          >
          value from output.text in presentation: p:\E-Switch Secure\PDF_dwgs \
          >
          ---
          >
          -dl
          >
          ---
          David Longnecker
          Web Developer

          >
          >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
          >>
          >
          >

          Comment

          Working...