Day.01.18 可变字符串

#import 

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        /*_________ 可变字符串 NSMutableString ______________________________________________________*/
        
        /**
         *      不可变字符串NSString 的对象一旦初始化,值不可更改
                可变字符串NSMutableString 的对象初始化后,可随时更改值
         */
        
        //1⃣️创建
        
//        NSMutableString *string = [NSMutableString stringWithFormat:@"NSMutableString->"];
        
            //空字符串
        
//        NSMutableString *string = [[NSMutableString alloc]init];
        
        NSMutableString *string = [NSMutableString string];
        
        //2⃣️属性
        
        //继承的length属性
        
        //3⃣️方法
        /**
         *  NSMutableString特有方法
         
            1.没有返回值,因为字符串可变,可修改值
            2.方法名也体现出没有返回值(有返回值的->stringBy.....)
         */
        
        //1.拼接字符串 appending
        
//        NSString *newstring = [string stringByAppendingFormat:@"----"];
        
        [string appendString:@"appendString->"];
        
        NSLog(@"%@",string);
        
        [string appendFormat:@"appendFormat<%p>",string];
        
        NSLog(@"%@",string);
        
        //2.插入字符串 insert
        
        [string insertString:@"$$$$$$" atIndex:10];
        
        NSLog(@"%@",string);
        
        //3.删除字符串 delete
        
        [string deleteCharactersInRange:NSMakeRange(0, 10)];
        
        NSLog(@"%@",string);
        
        //4.替换 replace
        [string replaceCharactersInRange:NSMakeRange(12, 10) withString:@"***********"];
        
        NSLog(@"%@",string);
        
        
        
        
    }
    return 0;
}

2016-01-18 20:26:33.850 03NSMutableString[4073:622737] appendString->
2016-01-18 20:26:33.852 03NSMutableString[4073:622737] appendString->appendFormat<0x10010b290>
2016-01-18 20:26:33.852 03NSMutableString[4073:622737] appendStri$$$$$$ng->appendFormat<0x10010b290>
2016-01-18 20:26:33.852 03NSMutableString[4073:622737] $$$$$$ng->appendFormat<0x10010b290>
2016-01-18 20:26:33.852 03NSMutableString[4073:622737] $$$$$$ng->ap***********<0x10010b290>
Program ended with exit code: 0

你可能感兴趣的:(Day.01.18 可变字符串)