NSMutableString可变字符串
2016-02-27 本文已影响198人
每日总结
初始化
NSMutableString *s1 = [NSMutableString stringWithCapacity:0];//通过设置空间来创建字符串对象;
NSMutableString *s3 = [@"123" mutableCopy];
添加字符串
[s1 appendFormat:@"abc"];
NSString *s2 = @"abc"
[s1 appendString:s2];
[s1 stringByAppendingString:@"123"];
插入字符串
[s1 insertString:@"123" atIndex:1];//atIndex后面加NSUInteger格式
重置字符串
[s1 setString:@"abc defg"];
删除部分字符
[s1 deleteCharactersInRange:NSMakeRange(2,3)];
改变部分字符
[s1 replaceCharactersInRange:NSMakeRange(1,2) withString:@"ABC"];