1

I have the following property:

public string InstanceName
{
    get
    {
        return cbServerInstanceName.Text;
    }
}

where the input for

cbServerInstanceName.Text = "ServerName\ PcName"

This is showing up as

 "ServerName\\ PcName" 

I tried using the string.replace but couldnt get it to work.

Any ideas?

Hans Rudel
  • 3,433
  • 5
  • 39
  • 62

2 Answers2

5

I'm going to take a stab at it and assume you're seeing "ServerName\\ PcName" using the debugger view in Visual Studio. Since it is showing you "a string\\" instead of a @"string literal\", you will see your slashes escaped. Just as you would with "\r\n" if you added a new-line.

If you can try printing your value to a MessageBox, or Debug or the Console. It should appear as you expect. fingers crossed

hometoast
  • 11,522
  • 5
  • 41
  • 58
5

When you are using C# and looking at strings in the debugger, it will escape certain characters and \ is one of them; it will show in the debugger as \\ but at runtime and not viewed in the debugger, it will be converted to a single \

vane
  • 2,125
  • 1
  • 21
  • 40