string sample="How to add doublequotes";
string str = '"'+sample+'"';
This is the output I am getting - "\"How to add doublequotes\""
I want the output as str= "How to add doublequotes"
I am using vs code19
string sample="How to add doublequotes";
string str = '"'+sample+'"';
This is the output I am getting - "\"How to add doublequotes\""
I want the output as str= "How to add doublequotes"
I am using vs code19
The output that appears in your debugger is not the output you'll receive on screen.
When printing this out to [Console / API / Website], everything will work as expected.
To see what I mean, try creating a console application with the following code on Main:
static void Main(string[] args)
{
string str = "\"This is with doublequotes\"";
Console.WriteLine(str);
}
BTW: You can just write string str = "\"How to add doublequotes\""
and it would still work.
If you use special characters or a newline in your text, you can use verbatim strings. They are denoted, by putting an @ before the string. Within a verbatim string, you don't need to escape special characters anymore, with one exception: the double quotes " need to be escaped using another double quotes:
string sample = @""How to add double quotes"";
When combining verbatim strings with interpolated strings, you ought to put the $ first:
string sample = $@"He said: ""Yes, for sure!"", but was only {p.Value} ÷ sure about it.";
Error Resolved by using this-
string query = "select * from customer where country = '" + USERNAME + "'";
Thanks everyone for investing your precious time!