12-6 NSMutableString

12-6 NSMutableString

#import 
//  可修改的字符串(NSMutableString)
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSString *str1 = @"This is a string.";
        NSMutableString *mstr;
        // insert code here...
        mstr = [NSMutableString stringWithString:str1];
        NSLog(@"mstr = %@", mstr);
        
        //  插入字符串
        [mstr insertString:@"hello " atIndex:10];
        NSLog(@"mstr = %@", mstr);
        
        //  追加字符串
        [mstr appendString:@"hello world"];
        NSLog(@"mstr = %@", mstr);
        
        //  删除字符串
        [mstr deleteCharactersInRange:NSMakeRange(10, 6)];
        [mstr deleteCharactersInRange:NSMakeRange(17, 11)];
        NSLog(@"mstr = %@", mstr);
        
        //  替换字符串
        [mstr replaceCharactersInRange:NSMakeRange(10, 6)withString:@"my string A"];
        NSLog(@"mstr = %@", mstr);
        
        [mstr setString:@"hello world"];
        NSLog(@"%@", mstr);
        
        
    }
    return 0;
}
12-6 NSMutableString_第1张图片
12-6 NSMutableString.png

你可能感兴趣的:(12-6 NSMutableString)