NSString Library... Anyone know of a helper library for NSString?
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:@","] => N开发者_如何学运维SArray
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:@","];
Some "quickies" for the NSString class, quite a handy reference to keep around: http://borkware.com/quickies/one?topic=NSString
http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/componentsSeparatedByString:
NSString *list = @"Norman, Stanley, Fletcher";
NSArray *listItems = [list componentsSeparatedByString:@", "];
http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/Strings/Articles/SearchingStrings.html#//apple_ref/doc/uid/20000149-CJBBGBAI
NSString *searchString = @"age";
NSString *beginsTest = @"Agencies";
NSRange prefixRange = [beginsTest rangeOfString:searchString
options:(NSAnchoredSearch | NSCaseInsensitiveSearch)];
// prefixRange = {0, 3}
精彩评论