简体   繁体   English

如何在NSString中找到最后一个子字符串?

[英]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? 如何在另一个NSString中获得最后一次出现的NSString? For example, in "abc def ghi abc def ghi," I want to find the index of the second "abc," not the first. 例如,在“abc def ghi abc def ghi”中,我想找到第二个“abc”的索引,而不是第一个。 I know I could do this with a bunch of rangeOfStrings, but is there already a function for that? 我知道我可以用一堆rangeOfStrings做到这一点,但是它已经有了这个功能吗?

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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