将char替换为NSString

ghi*_*boz 6 iphone nsstring str-replace nsmutablestring

我想简单地用"空白"字符替换"+"的所有事件......我尝试了这里列出的一些样本,也使用了NSSMutableString,但是程序崩溃了...从另一个中替换char的最佳方法是什么?谢谢

ken*_*ytm 13

如果要在适当位置替换可变字符串(NSMutableString):

[theMutableString replaceOccurrencesOfString:@"+"
                                  withString:@" "
                                     options:0
                                       range:NSMakeRange(0, [theMutableString length])]
Run Code Online (Sandbox Code Playgroud)

如果要创建新的不可变字符串(NSString):

NSString* newString = [theString stringByReplacingOccurrencesOfString:@"+"
                                                           withString:@" "];
Run Code Online (Sandbox Code Playgroud)