Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Modifying the Path

Modifying the Path

Scheduled Pinned Locked Moved C#
questiondatabaselearning
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AmbiguousName
    wrote on last edited by
    #1

    hello guys...I hae path stored in database which I retrieve successfuly. But before utilising them, I need to modify them. All of them have single backslah but of course, in order to use that path we need double backslash like this "\\". Here is what I have tried so far but it does not work of course. How can I do that?

            string path = "d:\\songs\\audio\\asd.mp3";
            string modifiedName = name.Replace("\\", "\\\\");
    
    L 1 Reply Last reply
    0
    • A AmbiguousName

      hello guys...I hae path stored in database which I retrieve successfuly. But before utilising them, I need to modify them. All of them have single backslah but of course, in order to use that path we need double backslash like this "\\". Here is what I have tried so far but it does not work of course. How can I do that?

              string path = "d:\\songs\\audio\\asd.mp3";
              string modifiedName = name.Replace("\\", "\\\\");
      
      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      overloaded Name wrote:

      of course ... we need double backslash

      No you don't. Backslash doubling is meaningful only to the compiler itself, it is how one says the next backslash is to be taken literally; once a string literal is compiled, all escape sequences have been interpreted and no double backslashes remain (unless you had 4 backslashes, which could be useful in a UNC). FWIW: Your code, corrected so it compiles, but totally useless, would be:

      string path = "d:\\\\songs\\\\audio\\\\asd.mp3";         // FIXED
      string modifiedName = path.Replace("\\\\", "\\\\\\\\");  // this says: replace 1 backslash by 2 backslashes!
      

      :)

      Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

      modified on Thursday, March 3, 2011 8:06 AM

      M 1 Reply Last reply
      0
      • L Luc Pattyn

        overloaded Name wrote:

        of course ... we need double backslash

        No you don't. Backslash doubling is meaningful only to the compiler itself, it is how one says the next backslash is to be taken literally; once a string literal is compiled, all escape sequences have been interpreted and no double backslashes remain (unless you had 4 backslashes, which could be useful in a UNC). FWIW: Your code, corrected so it compiles, but totally useless, would be:

        string path = "d:\\\\songs\\\\audio\\\\asd.mp3";         // FIXED
        string modifiedName = path.Replace("\\\\", "\\\\\\\\");  // this says: replace 1 backslash by 2 backslashes!
        

        :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        modified on Thursday, March 3, 2011 8:06 AM

        M Offline
        M Offline
        mabo42
        wrote on last edited by
        #3

        Hi Luc, Im sure you know that :), but the first line doesnt compile. Its an invalid string literal. One have to use

        strind path = @"d:\songs\audio\asd.mp3";

        or

        string path = "d:\\songs\\audio\\asd.mp3";

        Greets Matthias

        L 1 Reply Last reply
        0
        • M mabo42

          Hi Luc, Im sure you know that :), but the first line doesnt compile. Its an invalid string literal. One have to use

          strind path = @"d:\songs\audio\asd.mp3";

          or

          string path = "d:\\songs\\audio\\asd.mp3";

          Greets Matthias

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          My mistake, I copied and only fixed the second line. I'll fix it now. Thanks. :)

          Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups