NSString 中的原始字节使用什么编码

发布于 2024-10-04 08:44:29 字数 236 浏览 0 评论 0原文

我需要将 NSData 对象中的一些原始字节存储到 NSString (基本上是空编码)中,但我不确定如何执行此操作。显然,分配不正确的 8 位编码会很糟糕。 NSASCIIStringEncoding 不行,因为文档说“8 位字符内的严格 7 位 ASCII 编码;仅限 ASCII 值 0…127”。但我需要 0x0 - 0xFF 的全范围。

Base64 编码不是可接受的解决方案。

I need to store some raw bytes from NSData object into an NSString (basically a null encoding) but I am not sure how to do this. Obviously assigning an improper 8-bit encoding would be bad. NSASCIIStringEncoding is not OK because the docs say "Strict 7-bit ASCII encoding within 8-bit chars; ASCII values 0…127 only." but I need full range of 0x0 - 0xFF.

Base64 encoding is NOT an acceptable solution.

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

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

发布评论

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

评论(2

窗影残 2024-10-11 08:44:29

基本上,你不知道。

NSString 用于有效编码的字符串数据的字符串;通常为 UTF8 或 UTF16。 NSData 用于任意二进制数据。

如果要将原始字节存储到 NSString 中,则需要对它们进行编码,而 base64 是最常见的方法之一。

Basically, you don't.

An NSString is for strings of validly encoded string data; typically UTF8 or UTF16. NSData is for arbitrary binary data.

If you want to store raw bytes into an NSString, you need to encode them and base64 is one of the most common means of doing so.

弥枳 2024-10-11 08:44:29

使用 NSNEXTSTEPStringEncoding。根据文档

带有 NEXTSTEP 扩展的 8 位 ASCII 编码。

它出现在当前文档中(截至撰写本文时),并且在 Apple 和 GNU 的 (OPENSTEP) 标准实现中都可用。

警告:它没有说明这些“扩展”到底是什么,所以要小心。

Use NSNEXTSTEPStringEncoding. According to the documentation:

8-bit ASCII encoding with NEXTSTEP extensions.

It appears in the current documentation (as of writing this post) and is available in both Apple and GNU's implementation of the (OPENSTEP) standard.

Caveat: It doesn't state what exactly those "extensions" are, so tread lightly.

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