开发者

Convert NSData to NSString and ignore null bytes?

开发者 https://www.devze.com 2023-01-20 14:48 出处:网络
I need to convert a NSData object to an NSString. It is meant to be gibberish but I need it for debbuging.

I need to convert a NSData object to an NSString. It is meant to be gibberish but I need it for debbuging.

When I use N开发者_运维知识库SString's initWithData, it breaks as the data has NULL bytes. How can I make it ignore the null bytes and get a proper string?


Copy the NSData to a NSMutableData, byte by byte, skipping any null bytes. Then initialise the string from that.

0

精彩评论

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