iOS iOS-获取子字符串位置

这里需要用到正则表达式

NSString *superString = @"abcdeabc";
NSString *subString = @"ab";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:subString options:0 error:nil];
NSArray *matches =  [regex matchesInString:superString options:0 range:NSMakeRange(0, superString.length)]; 
[matches enumerateObjectsUsingBlock:^(NSTextCheckingResult * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
       NSRange range = obj.range;
}];

你可能感兴趣的:(iOS iOS-获取子字符串位置)