2009-08-29 100 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"]; 
相關問題