I have an NSMutable dictionary that contains file identifiers and their file name + extension in the simple form fileone.doc or filetwo.pdf. I need to determine what type of file the corresponding icon should display correctly in my UITableView. Here is what I have done so far.
NSString *docInfo = [NSString stringWithFormat:@"%d", indexPath.row];
I wrote two regular expressions to determine what type of file I am looking for, but they never return a positive result. I have not used regex in iOS programming before, so I'm not quite sure that I am doing it right, but basically copied the code from the class description page.
NSError *error = NULL; NSRegularExpression *regexPDF = [NSRegularExpression regularExpressionWithPattern:@"/^.*\\.pdf$/" options:NSRegularExpressionCaseInsensitive error:&error]; NSRegularExpression *regexDOC = [NSRegularExpression regularExpressionWithPattern:@"/^.*\\.(doc|docx)$/" options:NSRegularExpressionCaseInsensitive error:&error]; NSUInteger numMatch = [regexPDF numberOfMatchesInString:fileType options:0 range:NSMakeRange(0, [fileType length])]; NSLog(@"How many matches were found? %@", numMatch);
My questions would be, is there an easier way to do this? If not, is my regex wrong? And finally, if I have to use this, is it expensive at runtime? I donβt know how many files the user will have.
Thank.
regex objective-c iphone ios5 nsstring
TheJer Feb 11 '12 at 23:52 2012-02-11 23:52
source share