The whole array fits into the string, it's just that when you try to display it, only the part to the initial \0 displayed.
Here is the code illustrating this point:
unsigned char data[] = "hello\0world"; NSString *str = [[NSString alloc] initWithBytes:data length:sizeof(data) encoding:NSASCIIStringEncoding]; NSLog(@"%@", str); NSLog(@"%@", [str substringFromIndex:6]);
The result is the following log output:
hello world
source share