473,395 Members | 2,467 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 24397
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.