0

I am getting an array from php server like:

<__NSArrayM 0x7fe6326f2340>(
 01460367533.jpg,
 01460353708.jpg,
 01460354725.jpg,
 01460363165.jpg,
 01460364760.jpg,
 01460367938.jpg,
 ,
 11460353708.jpg,
 ,
 ,
 ,
 11460363173.jpg,
 11460364762.jpg,
 ,
 ,
 21460353708.jpg,
,
)

How can I remove empty string data (,) in NSMutableArray.

4
  • 2
    why and how are you adding the empty strings into the array to begin with? Commented Apr 11, 2016 at 11:43
  • agree with @Wain. just put a filter if it is empty just don't add it. Commented Apr 11, 2016 at 11:47
  • in server side i am getting this data how would i able to overcome this issue. Commented Apr 11, 2016 at 11:48
  • no idea, we know nothing about the server or the data, but when it arrives at the device you're still processing that and adding it to the array, what code does that? Commented Apr 11, 2016 at 11:49

3 Answers 3

4

You can create a non-empty array from mutable array.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"length > 0"];
NSArray *anotherArray = [yourMutableArray filteredArrayUsingPredicate:predicate];

Agree with the first comment, though. You should take care of it while adding data to array.

Sign up to request clarification or add additional context in comments.

Comments

3

You can remove multiple occurrence of multiple strings/objects.

NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"hello", @"", @"HI", @" ", nil];

[arr removeObjectsInArray:@[@"", @" "]];

NSLog(@"%@", arr);

Comments

1

I would suggest just use this simple one line of code

[mutableArrayOfStrings removeObject:@""];

to remove empty string items from your mutable string array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.