Convert NSData to NSString and ignore null bytes?

让人想犯罪 __ 提交于 2019-12-25 02:50:52

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/3949628/convert-nsdata-to-nsstring-and-ignore-null-bytes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!