0

Escape for double quotes??

In the previous lesson they said you need to use the escape character to use double quotes in a string but in this test is missing and apparently is ok. So do you need to escape the quotes or not?

25th Feb 2017, 8:10 PM
SSorin
SSorin - avatar
4 Respuestas
+ 2
If you created your string with double quotes and you're planning on using double quotes within your string then you will have to escape them. To avoid that you could just use single quotes when your string contains double quotes and double quotes When your string contains single quotes.
25th Feb 2017, 9:27 PM
Don
Don - avatar
+ 2
You don't need to escape any quotes if you enclose your srting into triple quotes: """I'm a "trple quoted" string.""" ... you just cannot have double or simple quote ending your string according the one you use ^^: '''That's a "string"''' is valid ( triple simple quote ), but: """That's a "string"""" isn't, as we use triple double quotes, we have four double quotes at end, which confuse interpreter :P
26th Feb 2017, 8:16 AM
visph
visph - avatar
+ 1
You can also use a string literal (String between triple single (or double) quotes) and there will be no need to escape double quotes. '''Jack said, "What is a string?" <-- That is!''' You won't need to escape single qoutes either, but if you place one right next to the beginning or ending set of single quotes you'll most likely get an error. So make sure that some other character separates them, even if it's a space. (same if you use double quotes)
25th Feb 2017, 10:25 PM
ChaoticDawg
ChaoticDawg - avatar
0
use \" like this: "That's a \"string\""
25th Feb 2017, 9:36 PM
André Morales
André Morales - avatar