Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no such method. You can use <code>rangeOfSubstring:options:range:</code> to get each match, and narrow down the range as you go: After each match, you change the search range's location to the character after (location + length of) the match range and reduce the search range's length by the difference.</p> <hr> <p>In the modern block-based world, it's not that hard to write <a href="https://gist.github.com/boredzo/8640626" rel="nofollow noreferrer">an “enumerate substrings that match…” method</a> that does the above as its implementation. Here's what that looks like:</p> <pre><code>- (NSUInteger) enumerateSubstringsMatchingString_PRH:(NSString *)stringToFind options:(NSStringCompareOptions)mask usingBlock:(void (^)(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop))block { NSUInteger count = 0; NSUInteger selfLength = self.length; NSRange searchRange = { 0, selfLength }; NSRange foundRange; BOOL stop = NO; while (( ! stop ) &amp;&amp; (foundRange = [self rangeOfString:stringToFind options:mask range:searchRange]).location != NSNotFound) { ++count; if (block != NULL) { @autoreleasepool { NSString *substring = [self substringWithRange:foundRange]; block(substring, foundRange, /*TODO include terminators and separators in enclosingRange as described in enumerateSubstringsWithOptions:: docs*/ foundRange, &amp;stop); } } searchRange.location = NSMaxRange(foundRange); if (searchRange.location &gt;= self.length) break; searchRange.length = selfLength - searchRange.location; } return count; } </code></pre> <p>The Gist I linked above gives a few obvious test cases.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload