I know that c# just prints the data inside double quotes:
Console.WriteLine("These two double quotes are removed when i am printed");`
And the output of it in console will be:
These two double quotes are removed when i am printed
But what I want to print on console is the same thing with double quotes:
"These two double quotes are removed when i am printed"
How do I do this. I am trying so because i have to write this output to a file where double quotes have significance.
To place quotation marks in a string in your code In Visual C# and Visual C++, insert the escape sequence \" as an embedded quotation mark.
A "string literal" is a sequence of characters from the source character set enclosed in double quotation marks (" "). String literals are used to represent a sequence of characters which, taken together, form a null-terminated string.
The basic double-quoted string is a series of characters surrounded by double quotes. If you need to use the double quote inside the string, you can use the backslash character.
When using double quotes "" to create a string literal, the double quote character needs to be escaped using a backslash: \" .
You need to escape the characters using \
:
Console.WriteLine("\"These two semi colons are removed when i am printed\"");
Also, the characters you are referring to ("
) are not semi-colons but quotation marks. A semi-colon is ;
.
Just add \
. See the String literals article
Console.WriteLine("\"These two semi colons are removed when i am printed\"");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With