mlfk.net
当前位置:首页 >> OBjECtivE%C中,NSString和BytE的转换 >>

OBjECtivE%C中,NSString和BytE的转换

NSString *str = @"AA21f0c1762a3abc299c013abe7dbcc50001DD"; NSData* bytes = [str dataUsingEncoding:NSUTF8StringEncoding]; Byte * myByte = (Byte *)[bytes bytes]; NSLog(@"myByte = %s",myByte);

这个问题得回归倒基础上面。字符串的长度跟编码有关系。utf8是变长,gbk是双字节 所以看如下代码 NSString *test = [NSString stringWithString:@"这是一个中文test1"];

NSData-> NSStringNSString *aString = [[NSString alloc] initWithData:adata encoding:NSUTF8StringEncoding];NSString->NSDataNSString *aString = @"1234abcd";NSData *aData = [aString dataUsingEncoding: NSUTF8StringEncoding];2.NSData...

NSString *str = @"AA21f0c1762a3abc299c013abe7dbcc50001DD"; NSData* bytes = [str dataUsingEncoding:NSUTF8StringEncoding]; Byte * myByte = (Byte *)[bytes bytes]; NSLog(@"myByte = %s",myByte);

网站首页 | 网站地图
All rights reserved Powered by www.mlfk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com