开发者

'Replace All' functionality for a file or NSString

I want to replace a particular substring from a file or a NSString with another string. This is like typical 'Replace All' functionality. Can you please suggest an开发者_开发问答y existing routine or function for this.

Thanks a lot. Really appreciate your help.


You can not edit a NSString. You need to use NSMutableString.

[myMutableString replaceOccurrencesOfString:@"target" withString:@"replacement" options:NSLiteralSearch range: NSMakeRange(0, [myMutableString length])];

Note : I have not compiled the code.


stringByReplacingOccurrencesOfString will do the job.

NSString *newString = [actualString stringByReplacingOccurrencesOfString:@"find substring" withString:@"replace with this"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜