0

Basically i want to split out everything inbetween the commas and add to an array and then get the count of this array and return it too.

I know its a mouthfull but someone will understand :P

Thanks

Mason

user393273
  • 1,430
  • 5
  • 25
  • 48
  • Functions usually do not return multiple values. – jwueller Dec 13 '10 at 12:01
  • 2
    possible duplicate of [NSString tokenize in Objective-C](http://stackoverflow.com/questions/259956/nsstring-tokenize-in-objective-c). The accepted answer returns an array of tokens. Getting the count from that should be obvious. – Marcelo Cantos Dec 13 '10 at 12:01
  • possible duplicate of [Objective-C Split()?](http://stackoverflow.com/questions/3558888/objective-c-split) – jwueller Dec 13 '10 at 12:04

2 Answers2

5

use componentsSeparatedByString:

Javal Nanda
  • 1,828
  • 3
  • 14
  • 26
0

Use this one:

-(NSInteger)countTotalWord:(NSString *) localString{
    //NSString *localString = @"My, Name, Is,Sudesh,Kumar ";
    //NSMutableArray *simplefyWordArray = [[NSMutableArray alloc] init];
    NSArray *wordSet = [localString  componentsSeparatedByString:@","];
   //for (int i=0 ;i<[wordSet count]; i++) {
       //NSString *trimedString = [[wordSet objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
       //[simplefyWordArray appendFormat:@"%@+",trimedString];
    //}
    return [wordSet count];
}
JeremyP
  • 84,577
  • 15
  • 123
  • 161
sudesh
  • 144
  • 2