How can we write " in nsstring?

微笑、不失礼 提交于 2019-12-17 18:52:35

问题


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.


来源:https://stackoverflow.com/questions/5551657/how-can-we-write-in-nsstring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!