iOS iOS-获取子字符串位置

2021-11-25  本文已影响0人  iOS程序媛ing

这里需要用到正则表达式

NSString *superString = @"abcdeabc";
NSString *subString = @"ab";
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:subString options:0 error:nil];
NSArray <NSTextCheckingResult *>*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;
}];
上一篇 下一篇

猜你喜欢

热点阅读