Reputation: 1427
I have NSString like this @"0,0,0,0,0,0,1,2012-03-08,2012-03-17"
. I want values separated by comma. I want values before comma and neglect comma.
I am new in iPhone, I know how to do in Java but not getting how to do in Objective-C.
Upvotes: 0
Views: 746
Reputation: 5520
for (NSString *s in [yourstring componentsSeparatedByString:@","])
{
int thisval = [s intValue];
}
Upvotes: 2
Reputation: 11839
NSString *string = @"0,0,0,0,0,0,1,2012-03-08,2012-03-17";
NSArray *componentArray = [string componentSeperatedByString:@","];
Upvotes: 9
Reputation: 95335
Use the componentsSeparatedByString:
method of 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);
}
Upvotes: 4