简体   繁体   中英

How do I find the last occurrence of a substring in an NSString?

How would I get the last occurrence of an NSString within another NSString? For example, in "abc def ghi abc def ghi," I want to find the index of the second "abc," not the first. I know I could do this with a bunch of rangeOfStrings, but is there already a function for that?

使用rangeOfString:options: ,在选项中包括NSBackwardsSearch

[@"abc def ghi abc def ghi" rangeOfString:@"abc" options:NSBackwardsSearch];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM