0

我有这样的 NSString @"0,0,0,0,0,0,1,2012-03-08,2012-03-17"。我想要用逗号分隔的值。我想要逗号之前的值并忽略逗号。

我是 iPhone 新手,我知道如何用 Java 做,但不知道如何用 Objective-C 做。

4

3 回答 3

9
NSString *string = @"0,0,0,0,0,0,1,2012-03-08,2012-03-17";

NSArray *componentArray = [string componentSeperatedByString:@","];
于 2012-05-18T08:15:38.310 回答
4

使用 的componentsSeparatedByString:方法NSString

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);
}
于 2012-05-18T08:14:16.027 回答
2
for (NSString *s in [yourstring componentsSeparatedByString:@","])
{
    int thisval = [s intValue];
}
于 2012-05-18T08:15:58.507 回答