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

一.NSData操作

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

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

  输出结果:

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

2. NSData类型的数据还原

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

  输出结果:

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

  

posted on 2016-06-25 18:03  chengkaihua  阅读(117)  评论(0编辑  收藏  举报