繁体   English   中英

Objective-C中的字符串解析

[英]String parsing in Objective-C

当我有pf:/Abc/def/ ,如何获得/Abc/def/

使用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];

参考: http : //developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/componentsSeparatedByString

componentsSeparatedByString将返回一个NSArray。 您可以在某个索引处获取该对象,然后在将其存储到另一个变量中时将其类型强制转换为NSString。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM