可变字符串的创建标签:NSRange,OC,height,NSMutableString,range,str,使用,字符串 From: https://blog.51cto.com/u_15907570/5925303
void
// 预先分配10个字数的存储空间
NSMutableString *str = [[NSMutableString alloc] initWithCapacity:10];
// 设置字符串内容
setString:@"1234"];
// 拼接一个字符串
appendString:@"567"];
// 拼接字符串
[str appendFormat:@"age is %i and height is %.2f", 27, 1.55f];
// 替换字符串
NSRange range = [str rangeOfString:@"height"];
//NSRange range = NSMakeRange(7, 3);
[str replaceCharactersInRange:range withString:@"no"];
// 插入字符串
[str insertString:@"abc" atIndex:2];
// 删除字符串
rangeOfString:@"age"];
[str deleteCharactersInRange:range];
NSLog(@"%@", str);
// 释放对象
release];
}
int main(int argc, const char
{
@autoreleasepool {
stringCreate();
}
return 0;
}