python
python

Reputation: 1427

How to get integer values from nsstring Evalution in iPhone?

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

Answers (3)

jimpic
jimpic

Reputation: 5520

for (NSString *s in [yourstring componentsSeparatedByString:@","])
{
    int thisval = [s intValue];
}

Upvotes: 2

rishi
rishi

Reputation: 11839

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

NSArray *componentArray = [string componentSeperatedByString:@","];

Upvotes: 9

dreamlax
dreamlax

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

Related Questions