NSString,NSMutableString

来源:互联网 发布:opencv 灰度共生矩阵 编辑:程序博客网 时间:2024/05/01 13:19

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 一下。

0 0
原创粉丝点击