如何在Objective-C中转义斜杠和引号?

时间:2022-09-15 15:35:48

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 个解决方案

#1


2  

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.

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

#1


2  

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.

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