Objective-c - NSMutableString

        //NSMutableString stringWithCapacity, stringWithString
NSMutableString *str1 = [NSMutableString stringWithCapacity:100];
NSMutableString *str2 = [NSMutableString stringWithString:@"Hello, 上海!"];
NSLog(@"str1 address: %p", str1);
NSLog(@"str2: %@", str2);

//NSMutableString appendFormat, appendString
[str1 appendFormat:@"苹果的iO"];
[str1 appendFormat:@"S, 很喜欢best!"];
NSLog(@"str1 appendFormat: %@", str1);
[str1 appendString:@"你呢?"];
NSLog(@"str1 appendString: %@", str1);

//NSMutableString deleteCharactersInRange
[str1 deleteCharactersInRange: [str1 rangeOfString:@"best"]];
NSLog(@"str1 deleteCharactersInRange: %@", str1);

//NSMutableString
[str1 insertString:@"系统" atIndex:(6)];
NSLog(@"str1 insertString:atIndex: %@", str1);

//NSMutableString assign/address
NSMutableString *str3 = str1;
NSLog(@"str1 address: %p", str1);
NSLog(@"str3 address: %p", str3);
NSLog(@"str3: %@", str3);

你可能感兴趣的:(Objective-C)