#import <Foundation/Foundation.h>
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 可变字符串
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...