开发者

how to change the char array to NSString [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜