gpt4 book ai didi

objective-c - objective-c 中的 char * 数组

转载 作者:太空宇宙 更新时间:2023-11-04 06:35:32 25 4
gpt4 key购买 nike

我有一个 c 字符串,需要它把它分成几行(我现在不会制作它们的 NSString)。有没有类似 NSMutableArray 的东西,我可以把这个 char * 放进去?或者我怎样才能实现它以从字符串中获取一些我以后可以通过索引访问的内容?

目前我在做

char *cline = strtok(data, "\n");
while(cline)
{
...
}

或者当我从磁盘读取文件时这样做更容易吗?

最佳答案

使用 NSValue将您的 char* 存储在 NSMutableArray 中

Overview

An NSValue object is a simple container for a single C or Objective-C data item. It can hold any of the scalar types such as int, float, and char, as well as pointers, structures, and object ids. The purpose of this class is to allow items of such data types to be added to collections such as instances of NSArray and NSSet, which require their elements to be objects. NSValue objects are always immutable.

关于objective-c - objective-c 中的 char * 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15395514/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com