Replacing a single occurrence of the string Obj-c

I am trying to replace only one of the NSString occurrences with another string. I know that you can use stringByReplacing * Occurrences * OfString ; however, this replaces all occurrences. What I'm looking for is more like stringByReplacing * Occurrence * OfString . If anyone could help me, that would be great. Thanks, Jnani

+5
source share
1 answer

Something like that?

NSRange location = [someString rangeOfString:stringToReplace];
NSString* result = [someString stringByReplacingCharactersInRange:location withString:stringToReplaceWith];
+9
source

All Articles