I am trying to create a String from Array.But, there is condition to how it should be generated, as explained below.
NSArray *array=[NSArray arrayWithObjects:@"Hello",@"World",nil];
[array componentsJoinedByString:@","];
This will output: Hello,World.
But, if first Item is Empty,then is there way to receive the only second one.
A static, plain-text Unicode string object which you use when you need reference semantics or other Foundation-specific behavior.
arrays can't contain nil. There is a special object, NSNull ( [NSNull null] ), that serves as a placeholder for nil.
An object representing a static ordered collection, for use instead of an Array constant in cases that require reference semantics.
Another way to do this is to grab a mutable copy of the array and just remove non valid objects. Something like this perhaps:
NSMutableArray *array = [[NSArray arrayWithObjects:@"",@"World",nil] mutableCopy];
[array removeObject:@""]; // Remove empty strings
[array removeObject:[NSNull null]]; // Or nulls maybe
NSLog(@"%@", [array componentsJoinedByString:@","]);
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