472,967 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,967 software developers and data experts.

Double BackSlashes

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
Jul 19 '05 #1
6 24243
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[i] == '\\')
{
temp.insert(i, 1, '\\');
++i; // Skip inserted char
}
cya

Christoph

Jul 19 '05 #2

"Mikheil" <mi****@global-erty.net> wrote in message
news:d8**************************@posting.google.c om...
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
Jul 19 '05 #3

"Mikheil" <mi****@global-erty.net> wrote in message
news:d8**************************@posting.google.c om...
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
Jul 19 '05 #4
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

Jul 19 '05 #5
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

Jul 19 '05 #6
Thank you guys!
You realy helped me.
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
7
by: Margaret MacDonald | last post by:
I've been going mad trying to figure out how to do this--it should be easy! Allow the user to enter '\_sometext\_', i.e., literal backslash, underscore, some text, literal backslash, underscore...
5
by: Aloysio Figueiredo | last post by:
I need to replace every ocurrence of '/' in s by '\/' in order to create a file named s. My first attempt was: s = '\/'.join(s.split('/')) but it doesn't work: >>> s = 'a/b' >>> s =...
2
by: wylbur37 | last post by:
When using a form with an input textbox such as the following ... <input type="text" name="field1" size=30> I discovered that when a backslash (\) is typed into the textbox, when I later check...
3
by: Stef Mientki | last post by:
It looks like sometimes a single backslash is replaced by a double backslash, but sometimes it's not ??? See the error message below, the first backslash is somewhere (not explicitly in my code)...
3
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
OpenFileDialog gives me the following, which I place in tbDevPath.Text: x:\\myVob\\mySolution\\mySolution.sln I really need this path to be single-backslashes, not double-backslashes, so I...
23
by: dkirkdrei | last post by:
I am having a bit of trouble trying to double up on slashes in a file path. What I am trying to do is very similar to the code below: <? $var =...
7
by: JohnF | last post by:
I have a function textag($expression){...} whose $expression argument is a string that can contain substrings like \alpha with one backslash or like a&b\\c&d with two backslashes. If I write...
6
by: Joseph Stateson | last post by:
I just started calling a php module from html. I added "php rocket" from microsoft to FP2003 but dont think that is the cause. The problem is that I am getting a backslash before a double or...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.