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?
+5
A:
Use rangeOfString:options:
, including NSBackwardsSearch
in the options.
[@"abc def ghi abc def ghi" rangeOfString:@"abc" options:NSBackwardsSearch];
outis
2010-03-13 21:46:40
haha +1 for beating me so badly ;)
Jason Coco
2010-03-13 21:49:58
Thanks a lot, saved me a lot of time.
Debashis
2010-03-13 21:52:20
@Jason: not so badly. It was a photo finish.
outis
2010-03-13 21:54:13
@Debashis: documentation is our friend.
outis
2010-03-13 21:54:52
Yup, I usually google things, so it passed my mind.
Debashis
2010-03-13 21:57:31