Coming from a ruby background, I'm wishing NSString had some convenient methods like the following:
[@"John" contains:@"ohn"] => BOOL
[@"1,2,3,4," split:@","] => NSArray
Anyone know of such an NSString helper library?
Coming from a ruby background, I'm wishing NSString had some convenient methods like the following:
[@"John" contains:@"ohn"] => BOOL
[@"1,2,3,4," split:@","] => NSArray
Anyone know of such an NSString helper library?
Try this:
BOOL contains = ([@"John" rangeOfString:@"ohn"].length == 0 ? NO : YES);
NSArray *array = [@"1,2,3,4" componentsSeparatedByString:@","];
NSString *list = @"Norman, Stanley, Fletcher";
NSArray *listItems = [list componentsSeparatedByString:@", "];
NSString *searchString = @"age";
NSString *beginsTest = @"Agencies";
NSRange prefixRange = [beginsTest rangeOfString:searchString
options:(NSAnchoredSearch | NSCaseInsensitiveSearch)];
// prefixRange = {0, 3}
Some "quickies" for the NSString class, quite a handy reference to keep around: http://borkware.com/quickies/one?topic=NSString