将 NSString 转换为 Char 数组
我有一个充满 NSString 的十六进制数组以及如何从中创建 char 数组。我不知道如何做到这一点。
所以我有一个数组
NSArray *myArray = [NSArray arrayWithObjects:@"0xAA", @"0xBB", @"0xCC", nil];
,我想创建 ac char 数组,与此类似的
const unsigned char testing[] = { 0xAA, 0xBB, 0xCC };
任何建议将不胜感激
谢谢
I have an array full of NSString's in hex and what to create a char array from them. I'm not sure how this can be done.
So I have an array
NSArray *myArray = [NSArray arrayWithObjects:@"0xAA", @"0xBB", @"0xCC", nil];
from this I want to create a c char array, something similar to this
const unsigned char testing[] = { 0xAA, 0xBB, 0xCC };
Any advice would be appreciated
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以采用 NSScaner 方法:
或 C 方法:
You can take the NSScaner approach:
Or the C approach:
使用 char test[] 定义了一个 char 数组。所以只能将一个字符串解析到该数组中。您必须定义
并在循环中填充它:
using char testing[] you are defined an array of char. So just a string can be parsed into that array. You have to define
and in a loop fill it with this: