如何将填充有十六进制值的 NData 转换为 NSString [英] How to convert NData populated with hex values to NSString

查看:73
本文介绍了如何将填充有十六进制值的 NData 转换为 NSString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSdata 对象,其中填充了一堆以十六进制格式设置的信息.我正在尝试将其转换为正确的字符串表示形式,但正在努力取得任何成功.

I have a NSdata object that is populated with a bunch of information thats formated in hex.. I am trying to convert it into its proper string representation but am struggling to have any success.

我尝试过的一件事是简单地将其放入 NSString 中,然后使用特殊字符标识符 thingy 将其 NSLog .. 忘记了单词 (%02x),但是要做到这一点,我将其编码为 NSUTF16 ..不想做..我很想看看我得到的数据到底是什么,看起来像一个 NSString.

One thing I have tried is to simply put it into a NSString and then NSLog it with a special character identifier thingy.. forgot the word (%02x), However to do this I am encoding it to NSUTF16.. which i dont want to do.. I mearly want to see exactly whats the data I am getting looks like as a NSString.

我这样做的原因是因为我稍后在我的代码中遇到了一些编码问题,我不确定是因为我收到的数据不正确还是我在处理的某个时候把它塞满了

The reason I am doing this is because I am having some issues with my encoding later on in my code and im not sure if its because the data I am receiving is incorrect or me stuffing it up at some point when I am handling it.

任何帮助将不胜感激.

推荐答案

您可以像这样获得 NSData 的字符串表示:

You can get a string representation of your NSData like so:

NSData *data = (your data)
NSString *string = [NSString stringWithCString:[data bytes] encoding:NSUTF8StringEncoding];

这是否回答了您的问题?

Does that answer your question?

这篇关于如何将填充有十六进制值的 NData 转换为 NSString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆