Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include quotes in a string

I have a string "I want to learn "c#"". How can I include the quotes before and after c#?

like image 672
learning Avatar asked Aug 11 '10 12:08

learning


People also ask

How do you add quotes to a string in Python?

' You can put a backslash character followed by a quote ( \" or \' ). This is called an escape sequence and Python will remove the backslash, and put just the quote in the string.

How do you put quotes in a string in Java?

To put quotation marks in a string in Java, use the backslash escape character before the quotation mark like so: \" .

How do you punctuate a quote with a string?

To enclose a quotation within a quotation, use… Place other punctuation (colons, semi-colons, question marks, etc.)… *Place other punctuation inside quotation marks when that punctuation is part of what is being quoted, such as a quoted question.

How do you print quotation marks in a string?

The first method to print the double quotes with the string uses an escape sequence, which is a backslash ( \ ) with a character. It is sometimes also called an escape character. Our goal is to insert double quotes at the starting and the ending point of our String.


2 Answers

Escape them with backslashes.

"I want to learn \"C#\"" 
like image 151
kennytm Avatar answered Sep 26 '22 10:09

kennytm


As well as escaping quotes with backslashes, also see SO question 2911073 which explains how you could alternatively use double-quoting in a @-prefixed string:

string msg = @"I want to learn ""c#"""; 
like image 40
NeilDurant Avatar answered Sep 22 '22 10:09

NeilDurant