如何获取 NSString 的 UTF8 二进制值
所以我想向我正在使用的服务器发送一个请求,它需要一个(utf-8格式的nsstring)的二进制值,如果有这样的事情,我已经读到NSStrings是unicode格式的......
基本上是想法是将 nsstring 的值发送到服务器,而不添加 UTF8 应用于字符串前面的 3 字节标头。这是因为服务器知道我将以二进制格式向它发送 UTF8 格式的字符串,因此为了保存可能会使我的请求膨胀的不必要的格式值,我想尝试这样做。
有人对我如何实现这一目标有任何想法吗?我目前正在苹果文档上阅读有关 NSStrings 的内容,但是有太多需要阅读和处理的内容,我希望有人能为我提供一些见解。
我没有任何代码可以显示该自动取款机,因为我仅处于规划和理解阶段,为了继续前进,我需要了解如何完成此操作,以便我可以开始对其进行编码:)
任何帮助都会不胜感激:)
So I am wanting to send a request to a server I am working with, it requieres the binary value of a (utf-8 formatted nsstring) if there is such a thing, I have read that NSStrings are unicode formatted...
basically the idea is to send the value of the nsstring to the server without the added 3 byte header that UTF8 applies to the front of a string. This is because the server knows I will be sending it UTF8 formatted string in binary format so to save unnessacery formatting values that could bloat my requests I would like to try and do it this way.
dose any one have any ideas on how I might achieve this? I'm currently reading up about NSStrings on the apple docs, but there is so much to read and process I'm hoping someone can provide me some insight.
I don't have any code to show for this atm because I'm only in the planning and understanding phase of this, and to move forward I need to understand how this might be done so I can start coding it :)
any help would be greatly appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NSString 有一个 UTF8String 方法。它返回字符,字符是字节。那有用吗?
返回值:
接收方的以 null 结尾的 UTF8 表示形式。
更多信息请点击此处。
https://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html
NSString has a UTF8String method. It returns chars and chars are bytes. Does that work?
Return Value:
A null-terminated UTF8 representation of the receiver.
more info on it here.
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html