NSData to NSString returns Null

前端 未结 3 1637
-上瘾入骨i
-上瘾入骨i 2021-01-08 00:27

I have searched. But still couldnt get it.

I\'m converting NSdata to NSString. When I do [data description]; it returns me <00000000 31323334 353637

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-08 00:55

    This may be because the first bytes of your data is 00. The character 0 is the end of string character. When creating a string from ASCII (from an array of chars or an array of bytes as you are doing), when the character 0 is encountered at the beginning, it produces an empty string.

    I would however expect it to return an instance of NSString with 0 characters, and not null.

提交回复
热议问题