replacing double \\ with single \

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahul23
    New Member
    • Apr 2013
    • 3

    replacing double \\ with single \

    Code:
      OpenFileDialog openFileDialog1 = new OpenFileDialog();
                    openFileDialog1.InitialDirectory = "C:\\Program Files\\Microsoft SQL Server\\MSSQL10_50.MSSQLSERVER\\MSSQL";
                    openFileDialog1.Filter = "Database files (*.mdf)|*.mdf";
                    openFileDialog1.FilterIndex = 2;
                    openFileDialog1.RestoreDirectory = true;
    
                    if (openFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        string file = openFileDialog1.FileName.Replace("\\",@"\");
                        txtFileName.Text = file;
    I am using this above code to replace double \\ with single \, but it's not working.
    Any suggestion.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    If \\ is an escape sequence, then to double up on \ in a string, you would need to escape it twice, \\\\

    Comment

    • SirZizo
      New Member
      • Apr 2013
      • 4

      #3
      i am test your code and there is no a problem

      Comment

      • rahul23
        New Member
        • Apr 2013
        • 3

        #4
        SirZizo
        there is a big problem, the data in textbox is ok, but just use a breakpoint on the textbox and on runtime you will file double \\ in the variable (string file).
        I need that one to be chaged

        Comment

        • rahul23
          New Member
          • Apr 2013
          • 3

          #5
          Rabbit
          Can you just put your code snippet for replacing double \\ with single \

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            rahul, that's probably just because it's showing the escape sequence. If the data shown in the textbox is fine, then it should be fine.

            Comment

            Working...