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”。