Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print double quotes (") in c# console application

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.

like image 902
xav xav Avatar asked Sep 10 '15 11:09

xav xav


People also ask

How do you print quotation marks in C?

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.

What is double quotation in C?

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.

How do you put a double quote in a 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.

How do you encode double quotes?

When using double quotes "" to create a string literal, the double quote character needs to be escaped using a backslash: \" .


2 Answers

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 ;.

like image 111
user1666620 Avatar answered Oct 18 '22 05:10

user1666620


Just add \. See the String literals article

Console.WriteLine("\"These two semi colons are removed when i am printed\"");
like image 27
Roman Marusyk Avatar answered Oct 18 '22 07:10

Roman Marusyk