Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

componentsSeparatedByString return 1 object when string is empty

I convert string into array by componentsSeparatedByString. It return array perfect. but when string is empty return 1 object.

why this happen ?

NSMutableArray *imagesList=[[[productDetail objectForKey:@"productImage"] componentsSeparatedByString:@","]mutableCopy];
like image 716
Pramod Tapaniya Avatar asked Sep 16 '25 08:09

Pramod Tapaniya


1 Answers

It is because, you are passing empty string("") and componentsSeparatedByString is trying to separate your string by comma(,) but their is no comma(,) in your string so it is returning 1 array item(that is "").

NSMutableArray *imagesList = [[NSMutableArray alloc]init];    
if(![productDetail isEqualToString:@""]) {   
    imagesList=[[[productDetail objectForKey:@"productImage"] componentsSeparatedByString:@","]mutableCopy];
}
like image 148
Sujay Avatar answered Sep 19 '25 04:09

Sujay