将 NSData 转换为 NSString 并忽略空字节?

发布于 2024-09-27 17:24:33 字数 130 浏览 0 评论 0原文

我需要将 NSData 对象转换为 NSString。它本来就是乱码,但我需要它来调试。

当我使用 NSString 的 initWithData 时,它会因为数据具有 NULL 字节而中断。如何让它忽略空字节并获得正确的字符串?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聽兲甴掵 2024-10-04 17:24:33

将 NSData 逐字节复制到 NSMutableData,跳过任何空字节。然后从中初始化字符串。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文