//2.将“文艺青年”改成“213青年”。
//方法1
NSString *str1 = @"文艺青年";
NSString *str2 = [str1 stringByReplacingOccurrencesOfString:@"文艺" withString:@"213" ];
NSLog(@"%@",str2);
//方法2
NSString *str1 = @"文艺青年";
NSString *str2 = [str1 stringByReplacingCharactersInRange:NSMakeRange(0, 2) withString:@"213"];
NSLog(@"%@",str2);
//方法3
NSMutableString *str1 = [NSMutableString stringWithFormat:@"文艺青年" ];
[str1 deleteCharactersInRange:NSMakeRange(0, 2)];
[str1 insertString:@"213" atIndex:0];
NSLog(@"%@",str1);
//方法4
NSMutableString *str1 = [NSMutableString stringWithFormat:@"文艺青年"];
[str1 setString:@"213青年"];
NSLog(@"%@",str1);
将“文艺青年”改成“213青年”
时间: 2024-10-13 21:28:41