不可变字符串 NSString 的对象一旦初始化,值不可更改
可变字符串 NSMutableString 的对象初始化后,可随时更改值
#import <Foundation/Foundation.h>
int main(int argc, const char *argv[])
{
@autoreleasepool
{
/*________________________可变字符串NSMutableString_________________*/
//1.创建
// NSMutableString *string = [NSMutableString stringWithFormat:@"NSMutableString ->"];
//空字符串
//NSMutableString *string = [[NSMutableString alloc]init];
NSMutableString *string = [NSMutableString string];
//属性
//集成length 属性
//方法
/*
NSMutableString 特有方法
1.没有返回值,因为字符串可变,可修改值
2.方法名也体现出没有返回值(有返回值的 -> 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;
}