Request: -(BOOL)[NSString containsString:] method
| Originator: | cedric.luthi | ||
| Number: | rdar://10482901 | Date Originated: | 23-Nov-2011 10:38 AM |
| Status: | Duplicate/7710615 | Resolved: | |
| Product: | iPhone SDK | Product Version: | 5.0 |
| Classification: | Enhancement | Reproducible: | Not Applicable |
Summary: I would like a containsString:(NSString *)substring method on NSString. Notes: Because [myString containsString:otherString] is much more readable than [myString rangeOfString:otherString].location != NSNotFound Also, everything works as expected if myString is nil, i.e. [nil containsString:@"x"] returns NO :-) [nil rangeOfString:@"x"].location != NSNotFound returns YES :-(
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Duped as 12322479
In the meantime, use a category to add the method
@interface NSString (containsString) -(BOOL)containsString:(NSString *)string; @end
@implementation NSString (containsString)
-(BOOL)containsString:(NSString *)string { return [self rangeOfString:string].location != NSNotFound; }
@end