NSMutableString的用法和注意事项

//

//  main.m

//  NSMutableString的用法和注意事项

//

//  Created by apple on 15/9/18.

//  Copyright (c) 2015 apple. All rights reserved.

//


#import


int main(int argc, const char * argv[]) {

    @autoreleasepool {

//1,追加

// -(void)appendString :(NSString *)aString;

// -(void)insertString :(NSString *)format,...NS_FORMAT_FUNCTION(1,2);

// 2,插入

// -(void)insertString :(NSString *)aString atIndex:(NSUInterger)loc;

// 3,删除

//-(void)deleteCharactersInRange:(NSRange)range;

        

// 4,替换

// -(void)replaceCharactersInRange:(NSRange )range withString :(NSString *)aString;NS

        NSMutableString *s=[NSMutableString string];

//追加

        [s appendString:@"123"];

        [s appendFormat:@"-%@-",@"abc" ] ;

         NSLog(@"%@",s);

        

 // 插入

        [s insertString:@"ABC" atIndex:1];

        NSLog(@"%@",s);

        

 //删除

        [s deleteCharactersInRange:NSMakeRange(2, 2)];

        NSLog(@"%@",s);

// 替换

        [s replaceCharactersInRange:NSMakeRange(2, 2) withString:@"aaaaa"];

        NSLog(@"%@",s);

  //易犯错误

        [s appendString:@"1Aaaaaa-abc-"];

        NSLog(@"%@",s);

    }

    return 0;

}


你可能感兴趣的:(NSMutableString的用法和注意事项)