iOS字符串和char类型数组之间的转换
2019-03-23 本文已影响0人
Hello小小酥
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);