1.NSMutableString的初始化
//1.与NSString初始化方法类似
NSMutableString *a1 = [NSMutableString stringWithFormat:@"%d",0];
NSMutableString *a2 = [NSMutableString stringWithUTF8String:"0"];
//2.可变空字符串初始化
NSMutableString *b = [NSMutableString string];
//3.不可变字符串变可变字符串
NSString *c1 = @"123";
NSMutableString *c2 = [NSMutableString stringWithString:c1];
//还可以写成
NSMutableString *c3 = [c1 mutableCopy];
2.NSMutableString的常用方法
//1.追加字符串
NSMutableString *str = [NSMutableString string];
[str appendString:[NSString stringWithFormat:@"%d",123]];
//2.追加新的格式化字符串
[str2 appendFormat:@"%d",456];
//3.删除方法(Range(x,y) x是从第几位开始删除,y是一共删除几位)
[str deleteCharactersInRange:NSMakeRange(0, 5)];
//4.插入字符(index值为在第几位上插入字符)
[str insertString:@"aaa" atIndex:0];
//5.替换字符串(Range(x,y) x是从第几位开始替换,y是一共替换几位)
[str replaceCharactersInRange:NSMakeRange(0, 3) withString:@"bbb"];