When I have pf:/Abc/def/
, how can I get the /Abc/def/
?
With Python, I can use
string = 'pf:/Abc/def/'
string.split(':')[1]
or even
string[3:]
What's开发者_StackOverflow社区 the equivalent function in Objective-C?
NSString *string = [NSString stringWithFormat:@"pf:/Abc/def/"];
NSArray *components = [string componentsSeparatedByString: @":"];
NSString *string2 = (NSString*) [components objectAtIndex:1];
Reference: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/componentsSeparatedByString:
componentsSeparatedByString will return an NSArray. You grab the object at a certain index, and type cast it to NSString when storing it into another variable.
精彩评论