如何在Objective-C中转义斜杠和引号? [英] How can I escape slashes and quotes in Objective-C?

查看:248
本文介绍了如何在Objective-C中转义斜杠和引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行以下操作:

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

在最后一个%@我想做< a href = %@> Hello< / a>

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

但我不知道如何正确转义吗?

But I am not sure how to escape it properly?

推荐答案

只需使用

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

如果以格式显示,或使用

if you put it in the format, or use

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

如果您使用%@ 格式字符串。 %@ 仅在 stringWithFormat:方法的第一个参数中解释。

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

这篇关于如何在Objective-C中转义斜杠和引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆