I’m trying to initialize a simple NSString from an unsigned char array (ASCII encoded). The problem is, that there are some \0s in the array as delimiters. If I use
[[NSString alloc] initWithBytes:bytes length:length encoding:NSASCIIEncoding];
I only get the part up to the first \0. Is there a way to get the amount of bytes specified in the length parameter even if there are \0s?
The entire array makes into the string, it is just that when you try displaying it only the portion up to the initial
\0is shown.Here is code to illustrate this point:
This produces the following log output: