如何在字符串中转义双引号?

时间:2009-08-29 20:37:52

标签: objective-c cocoa

我想在下面的字符串中出现双引号,所以它看起来像:

"hi there == "

这是我正在使用的代码:

NSMutableString *s = [[NSMutableString alloc] init];
[s appendString:@""""];
[s appendString:@"hi there == ""\n\r"];

相反,我只得到:

hi there ==

有什么想法吗?

3 个答案:

答案 0 :(得分:47)

[s appendString:@"hi there == \"\n\r"];

\""所需要的 - 这是标准的C格式。

答案 1 :(得分:1)

虽然已经晚了但我们可以试试这个:

sizeof(int*)

答案 2 :(得分:-2)

你必须在引号(“)之前附加一个斜杠(\)来表示预期的输出。

[s appendString:@"\"hi there == \"\n\r"];

输出将是“hi there ==”

相关问题