我有一个这样的字符串:
NSString *test = @"This is a test string";
我想用空格替换“测试”字,如下所示:
“这是一个字符串”
我怎么能做这样的事情?
我试过使用这个功能
test = [test stringByReplacingOccurrencesOfString:@"test" withString:@" "];
并没有正常工作。
我有一个这样的字符串:
NSString *test = @"This is a test string";
我想用空格替换“测试”字,如下所示:
“这是一个字符串”
我怎么能做这样的事情?
我试过使用这个功能
test = [test stringByReplacingOccurrencesOfString:@"test" withString:@" "];
并没有正常工作。
NSString *test = @"This is a test string";
test = [test stringByReplacingOccurrencesOfString:@" test" withString:@""];
NSLog(@"%@",test);
it should work, hope it helps. happy coding :)
NSString *test = @"This is a test string";
test = [test stringByReplacingOccurrencesOfString:@"test" withString:@""];
NSLog(@"%@",test);
Use this. No need to give space. it will replace that word with empty space.
使用 NSMutableString 代替 NSString.Repalce NSString *test = @"This is a test string" with NSMutableString *test = @"This is a test string";