In my App, data comes in String like this
"Hi,Hello,Bye"
I want to separate data by ","
How can I do that?
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];
NSString *str = @"Hi,Hello,Bye";
NSArray *aArray = [str componentsSeparatedByString:@","];
For more info, look at this post.
Well, the naïve approach would be to use componentsSeparatedByString:
, as suggested in the other answers.
However, if your data is truly in the CSV format, you'd do well to consider using a proper CSV parser, such as this one (which I wrote): https://github.com/davedelong/CHCSVParser
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With