Search code examples
iosnsrange

ios nsrange char from end


Let's say I have:

this - is an - example - with some - dashes

NSRange will pick up the first instance of "-" with `rangeOfString:@"-" but what if I only want the last one?

I'm looking for something that works similar to lastIndexOf in JS. Thanks!


Solution

  • One of the options you can pass to [NSString rangeOfString: options:] is NSBackwardsSearch (which would give you the last item in the string you're looking at).