0

我有一个这样的字符串:

NSString *test = @"This is a test string";

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

“这是一个字符串”

我怎么能做这样的事情?

我试过使用这个功能

test = [test stringByReplacingOccurrencesOfString:@"test" withString:@"    "];

并没有正常工作。

4

3 回答 3

0
NSString *test = @"This is a test string";
test = [test stringByReplacingOccurrencesOfString:@" test" withString:@""];
NSLog(@"%@",test);

it should work, hope it helps. happy coding :)

于 2012-05-14T12:37:44.103 回答
0
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.
于 2012-05-14T12:36:14.460 回答
0

使用 NSMutableString 代替 NSString.Repalce NSString *test = @"This is a test string" with NSMutableString *test = @"This is a test string";

于 2012-05-14T12:41:29.920 回答