Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating snippets with quotation marks inside

I have some code with quotation marks that I want to use as a snippet. Unfortunately, JSON requires me to use them in "body" array in my settings. I tried to use different types of quotation marks, but Visual Studio highlights it in red: enter image description here

What can I do to include quotation marks in my snippet?

like image 898
Piotrek Avatar asked Oct 28 '16 19:10

Piotrek


People also ask

How do you make your own snippets?

Create your own snippets# To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select the language (by language identifier) for which the snippets should appear, or the New Global Snippets file option if they should appear for all languages.

How do you make quotation marks?

Single quotation marks on Windows Press-and-hold the ALT key and then type 0145 for the opening single quotation mark and ALT followed by 0146 for the closing single quotation mark.


1 Answers

Use \ to escape the double quotes. A sample snippet looks like this:

"My quoted snippet": {
    "prefix": "quot",
    "body": [
        "Hello \"User\""
    ],
    "description": "Print snippets with quotes"
}

When you execute this snippet it will print: Hello "User"

like image 127
Wosi Avatar answered Sep 21 '22 06:09

Wosi