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);

字符串转换成字节数组 byte[] byBuffer = new byte[200]; String strInput="abcdefg"; byBuffer= strInput.getBytes(); 注意:如果字符串里面含有中文,要特别注意,在Android系统下,默认是UTF8编码,一个中文字符相当于3个字节,只有gb2312下...

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

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

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

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