Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 603
Debashis Avatar asked Mar 13 '10 21:03

Debashis


1 Answers

Use rangeOfString:options:, including NSBackwardsSearch in the options.

[@"abc def ghi abc def ghi" rangeOfString:@"abc" options:NSBackwardsSearch]; 
like image 200
outis Avatar answered Oct 22 '22 13:10

outis