Objective c 在目标c中用空格替换单词

Objective c 在目标c中用空格替换单词,objective-c,replace,nsstring,Objective C,Replace,Nsstring,我有这样一个字符串: NSString*test=@“这是一个测试字符串” 我想用空格替换“test”字,如下所示: “这是一个字符串” 我怎么能做这样的事 我已尝试使用此功能 test = [test stringByReplacingOccurrencesOfString:@"test" withString:@" "]; 而且效果不好 NSString *test = @"This is a test string"; test = [test stringByReplacingO

我有这样一个字符串:

NSString*test=@“这是一个测试字符串”

我想用空格替换“test”字,如下所示:

“这是一个字符串”

我怎么能做这样的事

我已尝试使用此功能

test = [test stringByReplacingOccurrencesOfString:@"test" withString:@"    "];
而且效果不好

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=@“这是一个测试字符串”,使用
NSMutableString*test=@“这是一个测试字符串”

您尝试该代码时给出的结果是什么?它应该让测试成为“thisastring”,我写的代码的输出是什么?这对我来说非常有效。
NSString *test = @"This is a test string";
test = [test stringByReplacingOccurrencesOfString:@" test" withString:@""];
NSLog(@"%@",test);