问题
I want to run stringByDeletingPathExtension
for all NSString members of an NSArray. How can I do this in Objective-C?
回答1:
NSArray *myArray = ... ;
[myArray makeObjectsPerformSelector:@selector(stringByDeletingPathExtension)];
EDIT: As @Wevah pointed out in the comments, this solution does not solve the problem, since stringByDeletingPathExtension returns a string rather than modified the object on which is invoked.
NSMutableArray *newArray = [[[NSMutableArray alloc] initWithArray:myArray] autorelease];
for( int i = 0; i < [newArray count]; i++ ) {
NSString* oneItem = [newArray objectAtIndex:i];
[newArray replaceObjectAtIndex:i withObject:[oneItem stringByDeletingPathExtension]];
}
then use your newArray ...
来源:https://stackoverflow.com/questions/5015050/equivalent-for-stringbydeletingpathextension-for-an-array