求教,IOS苹果开发中,怎样把byte [] 转成NSString ?

如下:
Byte keyByte[] = {0x08,0x08,0x04,0x0b,0x02,0x0f,0x0b,0x0c,0x01,0x03,0x09,0x07,0x0c,0x03,
0x07,0x0a,0x04,0x0f,0x06,0x0f,0x0e,0x09,0x05,0x01,0x0a,0x0a,0x01,0x09,
0x06,0x07,0x09,0x0d};
想转成NSString *类型的
最新回答
西风过纱

2024-07-01 00:49:41

Byte数组-> NSData
Byte byte[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};
NSData *adata = [[NSData alloc] initWithBytes:byte length:24];

NSData-> NSString
NSString
*aString = [[NSString alloc] initWithData:adata encoding:NSUTF8StringEncoding];
寄信给风

2024-07-01 12:18:56

Byte keyByte[] = {0x08,0x08,0x04,0x0b,0x02,0x0f,0x0b,0x0c,0x01,0x03,0x09,0x07,0x0c,0x03,
            0x07,0x0a,0x04,0x0f,0x06,0x0f,0x0e,0x09,0x05,0x01,0x0a,0x0a,0x01,0x09,
            0x06,0x07,0x09,0x0d};
        NSData *d = [NSData dataWithBytes:keyByte length:sizeof(keyByte)];
        NSStringEncoding encodeGB2312=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
        char byte[[d length]];
        for (int i = 0 ;i < [d length]; i++)
        {
            byte[i] = keyByte[i];
        }
        NSString *str = [NSString stringWithCString:byte encoding:encodeGB2312];
        NSLog(@"%@", str);
仲夏柠叶香

2024-07-01 04:28:21

[[NSString alloc]initWithData:data],基本样式是这样。如果帮到你,请采纳。
听雨的声音滴落

2024-07-01 13:18:52

http://blog.csdn.net/ernest201210/article/details/8079774
,推荐,
撸管冠军╮

2024-07-01 13:17:56

http://blog.csdn.net/ernest201210/article/details/8079774
,这个地址有详细的