Check and remove a specific row from an nmutable array without index

In Xcode, I store several NSString in an NSMutableArray .

 Hello Here MyBook Bible Array Name2 There IamCriminal 

User can enter a string.

 Name2 

I need to remove this particular row from NSMutableArray without knowing the row index. I have an idea that use iteration. Any other better way. Plz Give with Model Codes.

+6
source share
6 answers

you can use containsObject method in NSMutableArray

 if ([yourArray containsObject:@"object"]) { [yourArray removeObject:@"object"]; } 
+19
source
 [array removeObject:@"Name2"]; 

The documentation for the NSMutableArrays removeObject: object indicates:

Matches

defined based on the response of objects to isEqual: message

In other words, this method iterates through the array, comparing objects with @"Name2" . If the object is @"Name2" , it is removed from the array.

+8
source

Try it,

 BOOL flag = [arrayName containsObject:Str]; if (flag == YES) { [arrayName removeObject:Str]; } 
0
source
 [array removeObject:@"name2"]; 
0
source

You can try this

 for(NSString *string in array) { if([[string lowercasestring] isEqualToSring:[yourString lowercasestring]]) { [array removeObject:string]; break; } } 
0
source

You can just use

 [yourArray removeObject:stringObjectToDelete]; 

This method uses indexOfObject: to find matches, and then removes them using removeObjectAtIndex :. Thus, matches are determined based on the response of the objects to the isEqual: message. If the array does not contain anObject, the method has no effect.

0
source

All Articles