IOS NSData、NSString、char *转换,简洁明了

NSData <=> NSString

    NSString *str = @"fds";

    NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];

    str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];


NSString <=> char *

    NSString *str = @"fds";

    const char * aString =[str UTF8String];

    str = [NSString stringWithUTF8String:aString];


NSData <=> char *

    char *cChar = new char[12];

    NSData *data = [NSData dataWithBytes:cChar length:strlen(cChar)];

    cChar = (char *)[data bytes];


你可能感兴趣的:(char,NSData,NSString)