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 / C++ / MFC
  4. How to convert "D:\Documents\delay.txt" to "D:\\Documents\\delay.txt"?

How to convert "D:\Documents\delay.txt" to "D:\\Documents\\delay.txt"?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 4 Posters 1 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.
  • N Offline
    N Offline
    nhatvhm
    wrote on last edited by
    #1

    Hi all, I'm trying convert "D:\Documents\delay.txt" to "D:\\Documents\\delay.txt". Anybody can help me? Thank so much!

    Steve EcholsS M T 3 Replies Last reply
    0
    • N nhatvhm

      Hi all, I'm trying convert "D:\Documents\delay.txt" to "D:\\Documents\\delay.txt". Anybody can help me? Thank so much!

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #2

      Why? Escaping is handled at compile time, not runtime. But, depending on your platform, most of the string classes have a replace function. MFC: CString string1("D:\\Documents\\delay.txt"); string1.Replace("\\", "\\\\");


      - S 50 cups of coffee and you know it's on! A post a day, keeps the white coats away!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      N 1 Reply Last reply
      0
      • Steve EcholsS Steve Echols

        Why? Escaping is handled at compile time, not runtime. But, depending on your platform, most of the string classes have a replace function. MFC: CString string1("D:\\Documents\\delay.txt"); string1.Replace("\\", "\\\\");


        - S 50 cups of coffee and you know it's on! A post a day, keeps the white coats away!

        N Offline
        N Offline
        nhatvhm
        wrote on last edited by
        #3

        char *strFilePath = new char[1024];
        strFilePath = "D:\Documents\delay.txt";

        So, how to replay('\','\\'). I'm used C language.

        Steve EcholsS 1 Reply Last reply
        0
        • N nhatvhm

          char *strFilePath = new char[1024];
          strFilePath = "D:\Documents\delay.txt";

          So, how to replay('\','\\'). I'm used C language.

          Steve EcholsS Offline
          Steve EcholsS Offline
          Steve Echols
          wrote on last edited by
          #4

          Try: strcpy(strFilePath, "D:\\Documents\\delay.txt"); You need the double backslashes \\ in your string literal, because \ is the escape character, so the compiler is translating what you wrote as \D and \d. Lookup "C escape sequences" on google.


          - S 50 cups of coffee and you know it's on! A post a day, keeps the white coats away!

          • S
            50 cups of coffee and you know it's on!
            Code, follow, or get out of the way.
          1 Reply Last reply
          0
          • N nhatvhm

            Hi all, I'm trying convert "D:\Documents\delay.txt" to "D:\\Documents\\delay.txt". Anybody can help me? Thank so much!

            M Offline
            M Offline
            Mahesh Kulkarni
            wrote on last edited by
            #5

            Hi you can use strchr method in recursive order which will give u the "\" location. you have to just replace it as "\\" I think this is what looking for.

            The secret of life is not enjoyment but education through experience. - Swami Vivekananda.

            1 Reply Last reply
            0
            • N nhatvhm

              Hi all, I'm trying convert "D:\Documents\delay.txt" to "D:\\Documents\\delay.txt". Anybody can help me? Thank so much!

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              the good question is "why do you need to do this ?"... I suspect a dark reason which is in fact because you're trying to hack something because you don't actually understand that string escaping is useful only in your source code... if you're getting the string from an external source (input, textbox, open file dialog), the string you get is already good. you need to escape \ into \\ only in your source code, because if you don't, the \ character will try to escape the character next to it, and that's not what you want. you want a single \ in the string, because it is the folder separator character, which must be typed '\\'...

              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              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