-->

How can we write \" in nsstring?

2020-02-05 03:59发布

问题:

I have to initialize string as "Rose" including Quotation Mark. How to write " in our string?

回答1:

Escape the double quote with \

NSString *yourString = @"\"Rose\""; 


回答2:

Use the escape character: \

NSString *r = @"\"Rose\"";

You can find additional information about Escape character and String literal.



回答3:

Escape it with a backslash:

@"\"Rose\""


回答4:

Escape the quotation marks.

Example:

NSString *str = @"\"Rose\"";


回答5:

NSString *yourString = @"\"Rose\"";


回答6:

In swift 5, you can write with a hashtag :

 let raw = #"You can create "raw" strings in Swift 5."#

Output :

You can create "raw" strings in Swift 5.