0

The variable utfStringArray is type unsigned char ** and points some UTF-8 strings. How to convert this array to a type of NSArray * with same strings without using NSString *?

4

1 回答 1

0

我假设utfStringArray以 a 结尾NULL,否则您需要单独提供元素计数。我也假设ARC。注意我正在使用NSData,因为你已经规定NSString不能使用 's (出于某种原因):

unsigned char **utfStringArray = ...;
NSMutableArray *array = [[NSMutableArray alloc] init];
for (unsigned i = 0; utfStringArray[i] != NULL; i++)
{
    NSData *data = [NSData dataWithBytes:utfStringArray[i] 
                                  length:strlen(utfStringArray[i])];
    [array addObject:data];
}
于 2013-06-17T15:32:21.787 回答