Search code examples
iphoneobjective-ccocoa-touchios4

How to split items in a string separated by ","


In my App, data comes in String like this

"Hi,Hello,Bye"

I want to separate data by ","

How can I do that?


Solution

  • use componentsSeparatedByString:

    NSString *str = @"Hi,Hello,Bye";  
    NSArray *arr = [str componentsSeparatedByString:@","];  
    NSString *strHi = [arr objectAtIndex:0];  
    NSString *strHello = [arr objectAtIndex:1];
    NSString *strBye = [arr objectAtIndex:2];