开发者

Search a string with nsmutablearray contents

This is probably a quick and easy question, but how would I be able to search a str开发者_开发问答ing with the contents of a nsmutablearray which are strings. So I have the NSString *blah = @"djfald.ji". I have the nsmutablearray filled with different extensions and I want to search the string blah to see if any of the extensions have a match. I used to use -[NSRange rangeOfString:] but that doesn't work with arrays.

Thanks,

Kevin


If you really are dealing with path extensions, it's probably better to approach this the other way round. Something like:

NSString *extension = [@"djfald.ji" pathExtension];
BOOL found = [extensions containsObject:extension];


Simply use a block:

NSUInteger extIndex = [extensionArray indexOfObjectPassingTest:^(id obj, NSUInteger idx, BOOL *stop) {
  return [blah hasSuffix:obj];
}];
NSString *extension = extensionIndex == NSNotFound ? [extensionArray objectAtIndex extIndex] : nil;

Or simply loop through the array with an enumeration.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜