how to change the char array to NSString [closed]
for example I have a char array :
char array开发者_开发知识库[8];
i tried:
NSString *marketPacket = [NSString stringWithCString:array encoding:NSASCIIStringEncoding];
NSLog(@"%@",marketPacket);
but displays corrupted characters
char array[5] = {'a', 'b', 'c', 'd', '\0'};
NSString *marketPacket = [NSString stringWithCString:array encoding:NSASCIIStringEncoding];
NSLog(@"%@", marketPacket);
NSString is a class and you create an instance of it, so you have to put a * . If you create an array, just populate it to see something..
Change to
NSString *marketPacket
Should have given you a compiler error, actually. Strange. At least, assuming you copied and pasted the code, you need a pointer to NSString (as it is a Managed Object).
精彩评论