NSData是存储二进制的一种数据结构

一.NSData操作

1.字符串转换为NSData类型的数据

1
2
3
NSString *str = @"this is a string";
NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"data is %@",data);

  输出结果:

1
2
2016-06-27 23:24:13.502 OcTest[676:120833] data is <74686973 20697320 61207374 72696e67>
Program ended with exit code: 0

2. NSData类型的数据还原

1
2
NSString *str2 = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"str2 is %@",str2);

  输出结果:

1
2
2016-06-27 23:26:38.703 OcTest[688:128225] str2 is this is a string
Program ended with exit code: 0

  

posted on   chengkaihua  阅读(118)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示