不可變字符串 NSString 的對(duì)象一旦初始化情竹,值不可更改
可變字符串 NSMutableString 的對(duì)象初始化后掀淘,可隨時(shí)更改值
#import <Foundation/Foundation.h>
int main(int argc, const char *argv[])
{
@autoreleasepool
{
/*________________________可變字符串NSMutableString_________________*/
//1.創(chuàng)建
// NSMutableString *string = [NSMutableString stringWithFormat:@"NSMutableString ->"];
//空字符串
//NSMutableString *string = [[NSMutableString alloc]init];
NSMutableString *string = [NSMutableString string];
//屬性
//集成length 屬性
//方法
/*
NSMutableString 特有方法
1.沒有返回值几颜,因?yàn)樽址勺凃橇茫尚薷闹? 2.方法名也體現(xiàn)出沒有返回值(有返回值的 -> stringBy......)
*/
//1.拼接字符串 appending
//NSString *newstring = [string stringByAppendingFormat:@"---"];
[string appendString:@"appendString -> "];
NSLog(@"%@",string);
[string appendFormat:@"appendFormat<%p>",string];
NSLog(@"%@",string);
//2.插入字符串 insert
[string insertString:@"$$$" atIndex:10];
NSLog(@"%@",string);
//3.刪除字符串 delete
[string deleteCharactersInRange:NSMakeRange(0,10)];
NSLog(@"%@",string);
//4.替換 replace
[string replaceCharactersInRange:NSMakeRange(12,10) withString:@"***"];
NSLog(@"%@",string);
}
return 0;
}