Double BackSlashes

Discussion in 'C++' started by Mikheil, Aug 14, 2003.

  1. Mikheil

    Mikheil Guest

    Hello!
    I need to translate file destination name with one backslashes
    "c:\program files\directory\file.txt"
    to string containing double backslashes
    "c:\\program files\\directory\\file.txt"
    If there is a nativi function on C++, or any algolithms I'd be glad
    to know about them.
    Thank you
     
    Mikheil, Aug 14, 2003
    #1
    1. Advertising

  2. Mikheil wrote:
    > I need to translate file destination name with one backslashes
    > "c:\program files\directory\file.txt"
    > to string containing double backslashes
    > "c:\\program files\\directory\\file.txt"
    > If there is a nativi function on C++, or any algolithms I'd be glad
    > to know about them.


    Why not translate it to
    "c:/program files/directory/file.txt"?

    This should be far easier to accomplish and works too on any
    Windows OS. (ok, Im not sure about 3.11)

    Otherwise you could use std::string.find and insert (or replace)

    (untested):

    std::string temp = "c:\program files\directory\file.txt";

    for (int i = 0; i < temp.length(); ++i)
    if (temp == '\\')
    {
    temp.insert(i, 1, '\\');
    ++i; // Skip inserted char
    }


    cya

    Christoph
     
    Christoph Rabel, Aug 14, 2003
    #2
    1. Advertising

  3. "Mikheil" <> wrote in message
    news:...
    > Hello!
    > I need to translate file destination name with one backslashes
    > "c:\program files\directory\file.txt"
    > to string containing double backslashes
    > "c:\\program files\\directory\\file.txt"
    > If there is a nativi function on C++, or any algolithms I'd be glad
    > to know about them.
    > Thank you


    I think you are confused, a double backslash is just the way you write a
    single backslash in C++.

    "\\" - this string is a single backslash.

    "\\\\" - this string is a double backslash.

    If you have a string in memory with single backslashes then it will work to
    open a file. If you have a string in your program code, then you *type*
    double backslashes. There is no need to replace single backslashes with
    double blackslashes programmatically.

    john
     
    John Harrison, Aug 14, 2003
    #3
  4. "Mikheil" <> wrote in message
    news:...
    > Hello!
    > I need to translate file destination name with one backslashes
    > "c:\program files\directory\file.txt"


    This string does not have any backslashes

    \p, \d are illegal characters, \f is the form feed character.

    > to string containing double backslashes
    > "c:\\program files\\directory\\file.txt"


    This string has three single backslashes, \\ is the way you write a single
    backslash character. \\\\ is a double backslash character.

    > If there is a nativi function on C++, or any algolithms I'd be glad
    > to know about them.
    > Thank you


    john
     
    John Harrison, Aug 14, 2003
    #4
  5. Christoph Rabel wrote:

    > John Harrison wrote:
    >
    >> I don't think that will work. There are no blackslashes in your original
    >> string.

    >
    > Hmm, I can think of at least one case where it is necessary to write
    > double backslashes out to a file.


    Oops, misunderstood you. Of course it should be:

    std::string temp = "c:\\program files\\directory\\file.txt";

    thx for correcting me.

    Christoph
     
    Christoph Rabel, Aug 14, 2003
    #5
  6. Andrey Balaguta wrote:
    > Christoph Rabel wrote:
    >
    >>Why not translate it to
    >>"c:/program files/directory/file.txt"?
    >>
    >>This should be far easier to accomplish and works too on any
    >>Windows OS. (ok, Im not sure about 3.11)

    >
    > This will work?


    Probably. Depends on your needs.
    Its most of the time better to use / then \. Far less troubles,
    especially if you want to port the stuff one day.

    >What functions with? Will this work with stdlib?


    I dont understand where your questions aim. Maybe you could try to
    explain what you want to achieve. As John pointed out its most of the
    time not necessary to change anything.

    If \ or / works is OS specific, all std-functions only invoke the OS
    functions and give them the paths. So, if the OS knows how to interpret
    it, then it works.

    mfg

    Christoph
     
    Christoph Rabel, Aug 14, 2003
    #6
  7. Mikheil

    Mikheil Guest

    Thank you guys!
    You realy helped me.
     
    Mikheil, Aug 15, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    14,847
    Roedy Green
    Sep 5, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,443
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=

    GridView and Backslashes

    =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=, May 2, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    360
    =?Utf-8?B?TWF0dCBIYW1pbHRvbg==?=
    May 2, 2006
  4. Sydex
    Replies:
    12
    Views:
    6,564
    Victor Bazarov
    Feb 17, 2005
  5. Replies:
    6
    Views:
    376
Loading...

Share This Page