Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String matching objective-c

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

can you help me, please?

like image 465
Dany Avatar asked Dec 20 '10 23:12

Dany


People also ask

How do I check if a string contains another string in Objective C?

To check if a string contains another string in objective-c, we can use the rangeOfString: instance method where it returns the {NSNotFound, 0} if a 'searchString' is not found or empty (""). Output: string contains you!

What is Nsstring?

A static, plain-text Unicode string object which you use when you need reference semantics or other Foundation-specific behavior.


1 Answers

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) {

}
like image 91
Dan Rosenstark Avatar answered Sep 18 '22 19:09

Dan Rosenstark