开发者

Replacing a single occurrence of string Obj-c

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜