简体   繁体   中英

Convert NSData to NSString and ignore null bytes?

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 NSString'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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM