我有像这样@"0,0,0,0,0,0,1,2012-03-08,2012-03-17"
的NSString。我想要用逗号分隔的值。我想要逗号之前的值,而忽略逗号。
我是iPhone新手,我知道如何用Java做,但没有在Objective-C中做怎么做。
答案 0 :(得分:9)
NSString *string = @"0,0,0,0,0,0,1,2012-03-08,2012-03-17";
NSArray *componentArray = [string componentSeperatedByString:@","];
答案 1 :(得分:4)
使用NSString
的{{3}}方法。
NSString *str = @"0,0,0,0,0,0,1,2012-03-08,2012-03-17";
NSArray *components = [str componentsSeparatedByString:@","];
for (NSString *comp in components)
{
NSLog(@"%@", comp);
}
答案 2 :(得分:2)
for (NSString *s in [yourstring componentsSeparatedByString:@","])
{
int thisval = [s intValue];
}