Click here to Skip to main content
16,004,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi mates,

I have a problem recently. My prog is under C++/CLI WinForm App. I noticed that here when file path are used, they should be like:
"C:\\folder1\\underfolder\\file.JPG"

unlike C# and VB:
C#:   @"C:\folder1\underfolder\file.JPG"

VB:   "C:\folder1\underfolder\file.JPG"


The difference is between "\" and "\\".
That means, when you use "C:\folder1\..." to call or write a file, it's not acceptable in C++/CLI.
I used folderbrowserdialog to get the folderpath, which gets paths in form of
"C:\folder\...":
SQL
folderBrowserDialog1->ShowDialog();
String^ path = folderBrowserDialog1->SelectedPath;
\\ path = path->Replace("\", "\\"); 
textBox1->Text = path;


And then I want to replace the "\" into "\\" of the paths. The method I used is String.Replace(). But there is problem. The Replace() must be used in two ways:
1. Replace('a', 'b');
2. Replace("docment", "document");

But the replace of "\" to "\\" is not going to work. I am really confused.
Could you tell me how to solve it? Maybe there is other ways? Or was I wrong?
Is it a general problem in c++/cli that the paths must be used with "\\"?

Thanks in advance and happy Halloween!
Posted
Updated 31-Oct-12 20:47pm
v3

1 solution

Escape the backslashes by repeating them: Replace("\\", "\\\\");

See http://msdn.microsoft.com/en-us/library/h21280bw.aspx[^]
 
Share this answer
 
Comments
christmars 1-Nov-12 5:25am    
Thanks a lot!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900