hmcgeehan
asked on
Replace double backslash in a string
Hi
I have a string which (fro example) looks like this ...
C:\\temp\\MediaCoverage\\W aiting
I want to replace all '\\' with '\'
I try this ...
WaitingFolder = WaitingFolder.Replace("\\\ \", "\\");
WaitingFolder = WaitingFolder.Replace(@"\\ ", @"\");
but neither work
Any ideas?
thanks
I have a string which (fro example) looks like this ...
C:\\temp\\MediaCoverage\\W
I want to replace all '\\' with '\'
I try this ...
WaitingFolder = WaitingFolder.Replace("\\\
WaitingFolder = WaitingFolder.Replace(@"\\
but neither work
Any ideas?
thanks
no need to replace \\ to \, \\ is the escape to show character \ in C#.
ASKER
Raymond-Holmboe:
That gives me ....
C:whatevertempwhateverMedi aCoveragew hateverWai ting
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
That gives me ....
C:whatevertempwhateverMedi
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
ASKER
ryancys
If I don't do the replace then when I try to do this ....
if (System.IO.File.Exists(fil eToUpload) )
it says 'File not found'
If I give it a string with one \ instead of \\ it will work fine.
If I don't do the replace then when I try to do this ....
if (System.IO.File.Exists(fil
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....
and
String b = @"\";
both contain same value....
is fileToUpload returns a valid file name?
can you show the scripts to get fileToUpload ?
can you show the scripts to get fileToUpload ?
ASKER
String fileToUpload = @WaitingFolder + hfDocumentName.Value;
And WaitingFolder = "C:\\temp\\MediaCoverage\\ Waiting"
And WaitingFolder = "C:\\temp\\MediaCoverage\\
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hfDocumentName.Value contains "\\" at the start?
Doh it didn't
Sorry guys my bad!
thanks
Doh it didn't
Sorry guys my bad!
thanks
Did you try Replace("\\", "whatever") ?