Re: [問題] 字串前加@的意思?
※ 引述《iasm (魔術研究員)》之銘言:
: NSMutableString *mstr;
: mstr=[NSMutablestring stringwithstring: str1];
: [mstr insertString: @" mutable" atIndex:7];
: 最後的結果是"this is mutable string a";
: 而且實際上mstr這個mutable string其內的字串內容可以改
: 但為什麼要在 " mutable"前加代表常數的@呢
: 既然是給mutable string內容,加@就很矛盾了
: 煩請大家教教我,謝謝!!
1.mstr 是 mutable 的,所以 @" mutable" 就是 mutable?
這兩件事情沒有關係吧?
2.關於 @ 的意義,參見 http://tinyurl.com/24mtvg8 ,裡頭說
Defines a constant NSString object in the current module
and initializes the object with the specified string.
如果有 @,產生的才是 NSString 物件,如果你把 @ 拿掉,就會
變成 C 語言的 char *,加不加 @,重點不是設定成 Mutable 還是
inmutable,而是 ObjC 的字串還是 C 的字串。
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.128.103.143
→
05/05 01:46, , 1F
05/05 01:46, 1F
→
05/05 01:46, , 2F
05/05 01:46, 2F
推
05/05 19:05, , 3F
05/05 19:05, 3F
→
05/05 19:06, , 4F
05/05 19:06, 4F
討論串 (同標題文章)
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章