开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜