如何从iPhone中的字符串评估中获取整数值?

时间:2012-05-18 08:12:08

标签: iphone objective-c nsstring

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

我是iPhone新手,我知道如何用Java做,但没有在Objective-C中做怎么做。

3 个答案:

答案 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];
}