How can I escape slashes and quotes in Objective-C?

与世无争的帅哥 提交于 2019-12-20 07:34:55

问题


I would like to do the following

[controller setMessageBody:[NSString stringWithFormat:@"<strong>%@</strong> <br> <br> %@ <br><br> %@ <br><br> Sent From MyApp",self.articleTitle, self.articleDescription, self.articleURL] 
isHTML:YES];

on the last %@ I would like to do <a href="%@">Hello</a>

But I am not sure how to escape it properly?


回答1:


Just use

@"....<a href=\"%%@\">Hello</a>..."

if you put it in the format, or use

@"<a href=\"%@\">Hello</a>"

if you include it using %@ in the format string. The %@ is only interpreted in the first argument of the stringWithFormat: method here.



来源:https://stackoverflow.com/questions/3358293/how-can-i-escape-slashes-and-quotes-in-objective-c

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