2
当我有pf:/Abc/def/
时,如何获得/Abc/def/
?Objective-C中的字符串解析
使用Python,我可以使用
string = 'pf:/Abc/def/'
string.split(':')[1]
甚至
string[3:]
什么是Objective-C中的等效功能?
当我有pf:/Abc/def/
时,如何获得/Abc/def/
?Objective-C中的字符串解析
使用Python,我可以使用
string = 'pf:/Abc/def/'
string.split(':')[1]
甚至
string[3:]
什么是Objective-C中的等效功能?
NSString *string = [NSString stringWithFormat:@"pf:/Abc/def/"];
NSArray *components = [string componentsSeparatedByString: @":"];
NSString *string2 = (NSString*) [components objectAtIndex:1];
componentsSeparatedByString将返回一个NSArray。您在某个索引处抓取对象,并在将它存储到另一个变量中时将其转换为NSString。
我在第3行得到'无效初始化'(NSString string2 = ...) – prosseek 2011-02-19 04:12:46