Search code examples
iosobjective-cnsarray

how to convert nsstring to nsarray?


I have a string Afar,Abkhazian,Afrikaans,Amharic and i wish to convert it into the NSArray. Currently i am using the code:

  NSArray *languagesuserArray = [self.languagesOfUser componentsSeparatedByString:@""];

But next when i checked like this:

NSLog(@"Languages array %@",[languagesuserArray objectAtIndex:0]);

the output comes:

Afar,Abkhazian,Afrikaans,Amharic 

But i want only afar.. How to do this?


Solution

  • you need to seperate string by comma (,) not with blank space as your original string contains comma seperator.

     NSArray *languagesuserArray = [self.languagesOfUser componentsSeparatedByString:@","];
     NSLog(@"Languages array %@",[languagesuserArray objectAtIndex:0]);