标签:
NSMutableString可变字符串的创建
1 NSMutableString *string1 = [[NSMutableString alloc] init]; 2 //string2对象方法由创建,string3由类方法创建 3 NSMutableString *string2 = [[NSMutableString alloc] initWithCapacity:0]; 4 NSMutableString *string3 = [NSMutableString stringWithCapacity:0];
字符串的添加
1 NSMutableString *string = [[NSMutableString alloc] init]; 2 //- (void)appendString:(NSString *)aString; 3 //作用:在字符串后添加,不用创建新的字符串 4 [string appendString:@"bei jing ying nin"]; 5 NSLog(@"%@", string); 6 //- (void)insertString:(NSString *)aString atIndex:(NSUInteger)loc; 7 //作用:在字符串某位置插入字符串 8 [string insertString:@"huan" atIndex:8]; 9 NSLog(@"%@", string);
字符串的删除
NSMutableString *string = [[NSMutableString alloc] init]; [string appendString:@"bei jing huan ying nin"]; NSLog(@"%@", string); //- (void)deleteCharactersInRange:(NSRange)range; //作用:字符串的删除 NSRange range = {1, 5}; [string deleteCharactersInRange:range]; NSLog(@"%@", string);
iOS学习路之Objective-C(三)—— NSMutableString
标签:
原文地址:http://www.cnblogs.com/dyikai/p/4495350.html