#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//nsstring父类 NSMutableString可变字符串子类
NSMutableString *mustr=[[NSMutableString alloc]init];
NSMutableString *mustr1=[NSMutableString stringWithFormat:@"Hello"];
//将不可变的字符串放置到可变字符串内
NSString *[email protected]"welcome to oc";
mustr=[NSMutableString stringWithString:str];
//插入
[mustr insertString:@" students " atIndex:7];
[mustr appendString:@" teacher"];
[mustr appendFormat:@"第二遍插入:%@",str];
//删除
[mustr deleteCharactersInRange:NSMakeRange(8, 10)];
//查找并删除
NSRange rang=[mustr rangeOfString:@"第二遍插入:welcome to oc"];
if (rang.location!=NSNotFound) {
[mustr deleteCharactersInRange:rang];
}
//重新赋值
[mustr setString:str];
//替换
NSRange rang1=[mustr rangeOfString:@"oc"];
[mustr replaceCharactersInRange:rang1 withString:@"IOS"];
NSLog(@"%@",mustr);
}
return 0;
}