Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
I has enter
T4INTERN - 03\SQLEXPRESS
in textbox, then it is append in the string builder
StringBuilder ConStr = new StringBuilder.
ConStr.Append(txtServerName.Text.Trim());
Then i store that string in
string connection_string =ConStr.ToString();

But it gives me like this
T4INTERN - 03\\SQLEXPRESS.
I have to remove that one \ from it.

What I have tried:

I have tried
connstring=connstring.Replace(@"\\",@"\");
But it is not working.
Posted
Updated 7-May-18 7:09am
Comments
Thomas Daniels 7-May-18 12:54pm    
"it gives me like this" - where exactly do you see that string?
Member 11776570 7-May-18 12:58pm    
when i store it in the string variable
string connection_string =ConStr.ToString();
MadMyche 7-May-18 15:39pm    
Generally it is not recommended to build a connection string via concatenation, for reasons that parallel SQL Injection; there is actually a set of Connection String Builder classes which should be used if you are programmatically creating them

1 solution

It may sound strange but not all is what it seems to be...
The debugger will display string values as escaped string so " (double quote) will show as \" and \ (slash) will show as \\...
What character escape sequences are available? | C# Frequently Asked Questions[^]

You can tell Visual Studio not to do, by adding ',nq' to the variable name in the watch window...

Format Specifiers in C#[^]
 
Share this answer
 
v3
Comments
Thomas Daniels 7-May-18 13:30pm    
+5, especially for that ,ng trick - learning something new every day! :)
Kornfeld Eliyahu Peter 7-May-18 13:46pm    
Thank you...
Kornfeld Eliyahu Peter 7-May-18 16:11pm    
Ops... That 'ng' of course is 'nq' (no quotes)... Fixed and added the page with more...
Maciej Los 7-May-18 15:38pm    
5ed!
Kornfeld Eliyahu Peter 7-May-18 16:09pm    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900