2009-08-29 103 views
16

我想双引号以下字符串中出现,所以它看起来像:如何在字符串中跳出双引号?

"hi there == " 

下面是我使用的代码:

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

相反,我只得到:

hi there == 

有没有想法?

+7

应当注意的是 [秒appendString:@ “您好== ”“ \ n \ r”]; 无意中取C/C++/ObjC特征的优点:2串文字下放t彼此之间(有或没有空白在之间)连接在一起。 – jgottula 2009-08-29 20:45:09

回答

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

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

-2

你有引号(“)之前,追加一个斜杠(\),通用电气预期输出。

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

输出将是‘喜有==’

+3

- 1基本上只是在4年后重新发布现有答案的内容。顺便说一句,你的意思是“前置”而不是“追加”,在这里。 – 2015-01-02 12:22:52

0

虽然较晚,但我们可以尝试此:

[NSString stringWithFormat:@"\"Hi There=\" Other text"]; 
相关问题