来自红宝石背景,我希望NSString有一些方便的方法,如下所示:
[@"John" contains:@"ohn"] => BOOL
[@"1,2,3,4," split:@","] => NSArray
任何人都知道这样的NSString帮助程序库吗?
答案 0 :(得分:7)
试试这个:
BOOL contains = ([@"John" rangeOfString:@"ohn"].length == 0 ? NO : YES);
NSArray *array = [@"1,2,3,4" componentsSeparatedByString:@","];
答案 1 :(得分:5)
NSString类的一些“快速”,非常方便的参考:http://borkware.com/quickies/one?topic=NSString
答案 2 :(得分:2)
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}