Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove "\" from the string

string value = "SELECT dbo.GetDefaultType(\"PartnerType\") AS default_answer;"

How can i remove "\" from the above string.

Get the ref from here and tried,

value.Replace(@"\", "");
value.Replace(@"\", string.Empty);
like image 206
Smit Patel Avatar asked Sep 17 '25 07:09

Smit Patel


2 Answers

The \ isn't actually in the string it is only there to stop the double quotes from terminating the string literal early.

The string actually is SELECT dbo.GetDefaultType("PartnerType") AS default_answer;

value could just as easily been declared as

string value = @"SELECT dbo.GetDefaultType(""PartnerType"") AS default_answer;"

Where "" inside the string is still only a single quote "

like image 190
phuzi Avatar answered Sep 19 '25 20:09

phuzi


I'm pretty sure that you just see the value in the debugger and it shows the \ from the string literal. If you click at the loupe you would see the real string value which is:

SELECT dbo.GetDefaultType("PartnerType") AS default_answer; 

But to answer the question, if the string really was(including the declaration)

string value = "SELECT dbo.GetDefaultType(\"PartnerType\") AS default_answer;"

Then it could be initalized with this literal:

string value  = "string value = \"SELECT dbo.GetDefaultType(\\\"PartnerType\\\") AS default_answer;\"";

and you could really remove the backslashes with:

value = value.Replace("\\", "");
like image 22
Tim Schmelter Avatar answered Sep 19 '25 19:09

Tim Schmelter