开发者

Replacing a single occurrence of string Obj-c

开发者 https://www.devze.com 2023-04-02 10:51 出处:网络
I am trying to replace only one of the occurrences of a NSString with another string.I know that you can use stringByReplacing*开发者_C百科Occurrences*OfString; however, that replaces all occurrences.

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


Something like this?

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

精彩评论

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