Why does the following code create a registry below? Here's the anomaly: my second NSLog should print chrStr, but it doesn't produce anything, empty, which is checked by this debug command:
(gdb) po chrStr
object returns an empty description
However, the third NSString, where I re-convert the NSString back to an NSData object, displays the data, the same value as the first NSLog, as it should be. This indicates that chrStr should have the actual contents. But this does not seem to apply to the NSLOG or the po command. Why?
NSString *login;
NSString *pass;
login = @"Loginname";
pass = @"Password";
NSData *subData1 = [login dataUsingEncoding:NSUTF8StringEncoding];
NSData *subData2 = [pass dataUsingEncoding:NSUTF8StringEncoding];
NSMutableData *data = [NSMutableData data];
unsigned char zeroByte = 0;
[data appendBytes:&zeroByte length:1];
[data appendData:subData1];
[data appendBytes:&zeroByte length:1];
[data appendData:subData2];
NSLog(@"1.NSData: %@", data);
NSString *chrStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"2.NSString: %@", chrStr);
NSData *chrData = [chrStr dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"3.NSDATA: %@", chrData);
Gives: [1071: 207] 1.NSData: 004c6f67 696e6e61 6d650050 61737377 6f7264
[1071: 207] 2.NSString:
[1071: 207] 3.NSDATA: 004c6f67 696e6e61 6d650050 61737377 6f7264
. chrStr , 3-NSDATA , !
? , ://:
, uncommented , , , . , . , , , @ "\ 000% @\000% @", , . .