Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何在字符串中转义双引号?_Objective C_Cocoa - Fatal编程技术网

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

Objective c 如何在字符串中转义双引号?,objective-c,cocoa,Objective C,Cocoa,我希望在以下字符串中显示双引号,使其看起来像: "hi there == " 以下是我使用的代码: NSMutableString *s = [[NSMutableString alloc] init]; [s appendString:@""""]; [s appendString:@"hi there == ""\n\r"]; 相反,我只得到: hi there == 有什么想法吗 [s appendString:@"hi there == \"\n\r"]; \“是”所需的格式-这

我希望在以下字符串中显示双引号,使其看起来像:

"hi there == "
以下是我使用的代码:

NSMutableString *s = [[NSMutableString alloc] init];
[s appendString:@""""];
[s appendString:@"hi there == ""\n\r"];
相反,我只得到:

hi there ==
有什么想法吗

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

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

您必须在引号(“)之前附加斜杠(\)以生成预期的输出

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

输出将是“hi there==”

,虽然时间已晚,但我们可以尝试以下方法:

[NSString stringWithFormat:@"\"Hi There=\" Other text"];

应该注意的是[s appendString:@“hi there==”\n\r“];无意中利用了C/C++/ObjC功能:两个相邻的字符串文字(中间有或没有空格)连接在一起-​1用于4年后基本上只重新发布现有答案的内容。作为旁白,您的意思是“prepend”而不是“append”。