Link to home
Start Free TrialLog in
Avatar of gudidi
gudidiFlag for Israel

asked on

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
Avatar of Jon500
Jon500
Flag of Brazil image

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
Avatar of gudidi

ASKER

hi

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

10x
Avatar of gudidi

ASKER

sorry i ment double back slash...
ASKER CERTIFIED SOLUTION
Avatar of Jon500
Jon500
Flag of Brazil 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
Avatar of gudidi

ASKER

10x a lot.
you right. now i understand and it works fine now because the problem was in the script.
enjoy your points.

10x