NSString Library ...任何人都知道NSString的帮助程序库?

时间:2010-05-10 07:01:11

标签: iphone objective-c nsstring

来自红宝石背景,我希望NSString有一些方便的方法,如下所示:

[@"John" contains:@"ohn"] => BOOL
[@"1,2,3,4," split:@","] => NSArray

任何人都知道这样的NSString帮助程序库吗?

3 个答案:

答案 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)

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}