How can we write " in nsstring?

2020-02-05 03:33发布

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

6条回答
男人必须洒脱
2楼-- · 2020-02-05 04:05

Use the escape character: \

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

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

查看更多
We Are One
3楼-- · 2020-02-05 04:10

Escape the double quote with \

NSString *yourString = @"\"Rose\""; 
查看更多
一夜七次
4楼-- · 2020-02-05 04:13
NSString *yourString = @"\"Rose\"";
查看更多
太酷不给撩
5楼-- · 2020-02-05 04:13

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.
查看更多
虎瘦雄心在
6楼-- · 2020-02-05 04:15

Escape it with a backslash:

@"\"Rose\""
查看更多
欢心
7楼-- · 2020-02-05 04:18

Escape the quotation marks.

Example:

NSString *str = @"\"Rose\"";
查看更多
登录 后发表回答