How to Print Double Quotes Inside ""

How to print double quotes inside ?

With a backslash before the double quote you want to insert in the String:

let sentence = "They said \"It's okay\", didn't they?"

Now sentence is:

They said "It's okay", didn't they?

It's called "escaping" a character: you're using its literal value, it will not be interpreted.


With Swift 4 you can alternatively choose to use the """ delimiter for literal text where there's no need to escape:

let sentence = """
They said "It's okay", didn't they?
Yes, "okay" is what they said.
"""

This gives:

They said "It's okay", didn't they?

Yes, "okay" is what they said.


With Swift 5 you can use enhanced delimiters:

String literals can now be expressed using enhanced delimiters. A string literal with one or more number signs (#) before the opening quote treats backslashes and double-quote characters as literal unless they’re followed by the same number of number signs. Use enhanced delimiters to avoid cluttering string literals that contain many double-quote or backslash characters with extra escapes.

Your string now can be represented as:

let sentence = #"They said "It's okay", didn't they?"#

And if you want add variable to your string you should also add # after backslash:

let sentence = #"My "homepage" is \#(url)"#

Printing (double quote) in C

You can use escape symbol \" For example

puts( "\"This is a sentence in quotes\"" );

or

printf( "Here is a quote %c", '\"' );

or

printf( "Here is a quote %c", '"' );

How to print a string that contains quotes in python

Wrap it in single quotes.

print('AAA " AAA " AAA')
# => AAA " AAA " AAA

Or escape the quotes:

print("AAA \" \" AAA ")
# => AAA " " AAA

How to put double quotes into Swift String

You are doing everything right. Backslash is used as an escape character to insert double quotes into Swift string precisely in the way that you use it.

The issue is the debugger. Rather than printing the actual value of the string, it prints the value as a string literal, i.e. enclosed in double quotes, with all special characters properly escaped escaped.

If you use print(input) in your code, you would see the string that you expect, i.e. with escape characters expanded and no double quotes around them.

How would I print quotation marks in the output in C++?

escape the quote:

https://ideone.com/lcrYlA

#include <iostream>

int main()
{
// your code goes here
std::cout << " hello " << " \"world\"" << std::endl;
return 0;
}

You can of course do:

std::cout << author << " said \" "<< quote << "\"\n";

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

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

How to print double quotes () in R

Use cat:

cat("\" \"xml\" \"")

OR

cat('" "','xml','" "')

Output:

" "xml" "

Alternative using noqoute:

 noquote(" \" \"xml\" \" ")

Output :

 " "xml" " 

Another option using dQoute:

dQuote(" xml ")

Output :

"“ xml ”"


Related Topics



Leave a reply



Submit