views:

23

answers:

1

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 iteration to accomplish this?

Thanks!

A: 

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.

Jeremy W. Sherman
thanks for quick response! i ended up using a variation of your answer: inputString = (NSString*)[[parts subarrayWithRange:NSMakeRange(15,[parts count]-15)] componentsJoinedByString:@","];
Abbacore