Find all locations of substring in NSString (not just first)

后端 未结 6 1836
广开言路
广开言路 2020-11-30 04:12

There is a substring that occurs in a string several times. I use rangeOfString, but it seems that it can only find the first location. How can I find all the l

6条回答
  •  情话喂你
    2020-11-30 04:43

    Passing nil to [string rangeOfString:substring options:nil range:searchRange]; shows a warning.

    To get rid of the warning, put in an enum from this group

    enum {
       NSCaseInsensitiveSearch = 1,
       NSLiteralSearch = 2,
       NSBackwardsSearch = 4,
       NSAnchoredSearch = 8,
       NSNumericSearch = 64,
       NSDiacriticInsensitiveSearch = 128,
       NSWidthInsensitiveSearch = 256,
       NSForcedOrderingSearch = 512,
       NSRegularExpressionSearch = 1024
    };
    

    https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/index.html#//apple_ref/doc/constant_group/Search_and_Comparison_Options

提交回复
热议问题