I need to match my string in this way: *myString*
where *
mean any substring.
which method should I use?
can you help me, please?
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!
A static, plain-text Unicode string object which you use when you need reference semantics or other Foundation-specific behavior.
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) {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With