String matching objective-c

Dany picture Dany · Dec 21, 2010 · Viewed 11.4k times · Source

I need to match my string in this way: *myString* where * mean any substring. which method should I use?

can you help me, please?

Answer

Dan Rosenstark picture Dan Rosenstark · Dec 21, 2010

If it's for iPhone OS 3.2 or later, use NSRegularExpressionSearch.

NSString *regEx = [NSString stringWithFormat:@".*%@.*", yourSearchString];
NSRange range = [stringToSearch rangeOfString:regEx options:NSRegularExpressionSearch];
if (range.location != NSNotFound) {

}