replace double back slash with single one

Hi Experts

i have a string which contain path with double back slash and i need to replace it before run the query with
single back slash. nothing work now. any idea?

string sPath1="";
sPath1 = this.Path;         // current value: C:\\ORADATA\\SPI2009
sPath1 = sPath1.Replace("\\\\", "\\");
sPath1 = sPath1.Replace(@"\\", @"\");

none of 2 option is works.

10x
gudidiAsked:
Who is Participating?
 
Jon500Connect With a Mentor Commented:
Are you using C#? I understood that you are.

Perhaps you did not understand my message. You only HAVE a single backslash. Your string is

C:\ORADATA\SPI2009

You only think it has double backslashes because that is what the C# watch window shows. If you inspect the LENGTH of the string after you do your replace, you will see that it is 18 (single backslashes) and not 20 (doubled backslashes).

Regards,
Jon500
0
 
Jon500Commented:
Hi,

Well, you're really more correct than you think. :)

I like to use this syntax:
"\\any\\".Replace("\0x005C\0x005C","\0x005C")

If you inspect the value of the above in the Visual Studio debugger, you will see:
"\\any\\"

You will then conclude that it did not work. But if you try this:

"\\any\\".Replace("\0x005C\0x005C","\0x005C").Length

You will see that the length is 5--2 for each "\" and 3 for "any". In other words, the string is correct even though it doesn't look that way in the watch window.

Your first AND second examples above are actually correct. :)

Regards,
Jon500
0
 
gudidiAuthor Commented:
hi

this path is a part of query for Oracle,
the Oracle can not accept double quote so i need to remove it.

10x
0
 
gudidiAuthor Commented:
sorry i ment double back slash...
0
 
gudidiAuthor Commented:
10x a lot.
you right. now i understand and it works fine now because the problem was in the script.
enjoy your points.

10x
0
All Courses

From novice to tech pro — start learning today.