The %c
format does not produce any output for the NULL character, but is does also
not terminate the string. See the following example:
NSMutableString * newString = [[NSMutableString alloc] init];
[newString appendFormat:@"%c", 0x30]; // the '0' character
[newString appendFormat:@"%c", 0x00]; // the NULL character
[newString appendFormat:@"%c", 0x31]; // the '1' character
NSLog(@"newString is %@", newString);
// Output: newString is 01
NSLog(@"length is %ld", newString.length);
// Output: length is 2
So you can not expect to get any output for the hex input 00
. In particular, you can not
expect to get the character "0" because that has the ASCII code hex 30
, not 00
.
Note that you can convert NSData
to NSString
directly using
NSString *s = [[NSString alloc] initWithData:data encoding:encoding];
if data
represents a string in some encoding, e.g. UTF-8 (which is not the case with
your data).
A better answer might be possible if you explain what the data represents and what string representation of the data you want.