'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"];
精彩评论