Click here to Skip to main content
11,636,300 members (74,432 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++/CLI C# .NET WinForm
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:
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
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 30-Oct-12 21:24pm
Edited 31-Oct-12 20:47pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

christmars at 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
0 295
1 Sergey Alexandrovich Kryukov 275
2 OriginalGriff 233
3 Suvendu Shekhar Giri 225
4 stibee 215
0 OriginalGriff 8,941
1 Sergey Alexandrovich Kryukov 8,459
2 Mika Wendelius 6,849
3 F-ES Sitecore 2,364
4 Suvendu Shekhar Giri 2,320

Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 1 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100