NSString *str=@"welcome to oc";//字符串常量不能放在可变字符串中,应该放在不可变的字符串中
mustr=[NSMutableString stringWithString:str];//把不可变字符串放入可变字符串中
NSLog(@"%@",mustr);
//插入
[mustr insertString:@" students"atIndex:7];//在指定位置插入字符串
[mustr appendString:@" teacher"];//在末尾插入字符串
[mustr appendFormat:@"第二遍插入:%@",str];//在末尾格式化插入字符串
NSLog(@"%@",mustr);
//删除
[mustr deleteCharactersInRange:NSMakeRange(8,9)];
NSLog(@"%@",mustr);
//查找并删除
NSRange rang=[mustr rangeOfString:@"teacher"];
if (rang.location!=NSNotFound) {
[mustr deleteCharactersInRange:rang];
}
NSLog(@"%@",mustr);
//重新赋值
[mustr setString:str];
NSLog(@"%@",mustr);
//替换
NSRange rang1=[mustr rangeOfString:@"oc"];
[mustr replaceCharactersInRange:rang1 withString:@"IOS"];
NSLog(@"%@",mustr);