Link to home
Start Free TrialLog in
Avatar of hmcgeehan
hmcgeehan

asked on

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
Avatar of Raymond-Holmboe
Raymond-Holmboe

Hi

Did you try Replace("\\", "whatever") ?
Avatar of Ryan Chong
no need to replace \\ to \, \\ is the escape to show character \ in C#.
Avatar of hmcgeehan

ASKER

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
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.
String a = "\\";

and

String b = @"\";


both contain same value....
is fileToUpload returns a valid file name?

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

And WaitingFolder = "C:\\temp\\MediaCoverage\\Waiting"
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hfDocumentName.Value contains "\\" at the start?

Doh it didn't
Sorry guys my bad!
thanks