NSString,NSMutableString,nsstring

來源:互聯網
上載者:User

NSString,NSMutableString,nsstring
NSString

NOTE

An immutable string is a text string that is defined when it is created and subsequently cannot be changed. An immutable string is implemented as an array of Unicode characters (in other words, a text string). To create and manage an immutable string, use the NSString class. To construct and manage a string that can be changed after it has been created, use NSMutableString.

NSString 管理自符串的對象
內容:唯讀,不可改變

注意點:如果要繼承NSString 必須重載characterAtIndex: 和length 這兩個方法
編碼方式:unicode,這個方法availableStringEncodings 可查看提供的編碼,當我門從其他類型的字串轉換的時候可以指定編碼。

NString 自符串 常量 和C語言一樣 他們在編譯的時候,會在一個常量區裡,直到程式運行完畢後才被釋放。

NSMutableString

他是NSString子類,只一個一個可變的地區

編程中容易犯的錯誤
當函數傳回型別是NSString 時 ,函數返回的是NSMutableString,這樣是沒有錯的,但是接受傳回值的變數指向卻是NSMutableString,一不小心改變了,變數也會跟著變,這時我們需要copy 一下。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.