Question

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?

Was it helpful?

Solution

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 \

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top