ignoring a range of items from an nsarray
I have an NSArray
of unknown items. I know there will always be more than 10 items.
I would like to assign all but the first 10 items to an NSString
.
Something like:
NSString *itemString = (NSString*)[itemArray StartingIndex:10];
Is there a simple efficient way without开发者_Python百科 iteration to accomplish this?
Thanks!
The array is most likely iterating for you, but you can do this:
NSRange allButFirstTen = NSMakeRange(10, [itemArray count] - 10);
NSString *itemStrings[allButFirstTen.count];
[itemArray getObjects:itemStrings range:allButFirstTen];
/* |itemStrings| is now an array of NSString pointers
* corresponding to all but the first 10 items of |itemArray|. */
NSString *firstString = itemStrings[0];
It's possible what you mean is that you want to concatenate every item in the array except the first ten into a single string. In that case, you are going to have to do your own iteration to perform the concatenation.
精彩评论