忽略 nsarray 中的一系列项目

发布于 2024-09-27 16:28:12 字数 256 浏览 0 评论 0原文

我有一个未知项目的 NSArray 。我知道总会有超过 10 个项目。

我想将除前 10 个项目之外的所有项目分配给 NSString

比如:

NSString *itemString = (NSString*)[itemArray StartingIndex:10];

是否有一种简单有效的方法无需迭代即可完成此任务?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌梦深 2024-10-04 16:28:12

该数组很可能会为您进行迭代,但您可以这样做:

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];

您的意思可能是您想要将数组中除前十项之外的每个项目连接到单个字符串中。在这种情况下,您将必须执行自己的迭代来执行串联。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文