Replace double backslash in a string

Hi

I have a string which (fro example) looks like this ...

C:\\temp\\MediaCoverage\\Waiting

I want to replace all '\\' with '\'

I try this ...

WaitingFolder = WaitingFolder.Replace("\\\\", "\\");
WaitingFolder = WaitingFolder.Replace(@"\\", @"\");

but neither work

Any ideas?

thanks
hmcgeehanAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raymond-HolmboeCommented:
Hi

Did you try Replace("\\", "whatever") ?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
no need to replace \\ to \, \\ is the escape to show character \ in C#.
0
hmcgeehanAuthor Commented:
Raymond-Holmboe:

That gives me ....
C:whatevertempwhateverMediaCoveragewhateverWaiting

So it does work for that ....

But if I do

string newWaitingFolder = WaitingFolder.Replace("\\", @"\");

it doesn't change the original string.

And if I do
string newWaitingFolder = WaitingFolder.Replace("\\", "\");
it won't compile
Error      1      Newline in constant

thanks
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

hmcgeehanAuthor Commented:
ryancys

If I don't do the replace then when I try to do this ....

if (System.IO.File.Exists(fileToUpload))

it says 'File not found'

If I give it a string with one \ instead of \\ it will work fine.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
String a = "\\";

and

String b = @"\";


both contain same value....
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
is fileToUpload returns a valid file name?

can you show the scripts to get fileToUpload ?
0
hmcgeehanAuthor Commented:
String fileToUpload = @WaitingFolder + hfDocumentName.Value;

And WaitingFolder = "C:\\temp\\MediaCoverage\\Waiting"
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
hfDocumentName.Value contains "\\" at the start?

if it's not, you may try this instead:

...

String WaitingFolder = @"C:\temp\MediaCoverage\Waiting\";

then:

String fileToUpload = WaitingFolder + hfDocumentName.Value;

...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hmcgeehanAuthor Commented:
hfDocumentName.Value contains "\\" at the start?

Doh it didn't
Sorry guys my bad!
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.