replace double back slash with single one

Posted on 2009-12-31
Last Modified: 2013-12-17
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.

Question by:gudidi
    LVL 8

    Expert Comment


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

    I like to use this syntax:

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

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


    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. :)


    Author Comment


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


    Author Comment

    sorry i ment double back slash...
    LVL 8

    Accepted Solution

    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


    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).


    Author Comment

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    This video discusses moving either the default database or any database to a new volume.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now