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

In my application, the data goes to String as follows

"Hi,Hello,Bye"

I want to split the data into ","

How can i do this?

+5
source share
6 answers

use SeparatedByString components:

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

NSArray *aArray = [str componentsSeparatedByString:@","];

See more details.

+7
source

, componentsSeparatedByString:, .

, CSV, CSV, ( ): https://github.com/davedelong/CHCSVParser

+4

[myString componentsSeparatedByString:@","].

+2
+1
NSArray *components = [@"Hi,Hello,Bye" componentsSeparatedByString:@","];

Apple String .

+1