开发者

'Replace All' functionality for a file or NSString

开发者 https://www.devze.com 2023-01-24 07:38 出处:网络
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 o

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

精彩评论

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