iOS字符串和char类型数组之间的转换

NSString转char类型数组

NSString *aaa = @"abcdefg";
    unsigned char css[aaa.length];
    memcpy(css, [aaa cStringUsingEncoding:NSUTF8StringEncoding], aaa.length);
    for (int i = 0; i < sizeof(css); i++) {
        NSLog(@"%d======%c",i,css[i]);
    }

char数组转NSString,这里就直接遍历拼接

NSMutableString *mustr = [NSMutableString string];
    for (int i = 0; i < sizeof(css); i++) {
        [mustr appendFormat:@"%c",css[i] ];
    }
    NSLog(@"%@",mustr);

你可能感兴趣的:(iOS字符串和char类型数组之间的转换)