把nsstring*转换成char*(包含两个方法)
#import
int main(int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
NSString * str = @"你好";
const char *s = [str UTF8String];
printf("%s\n",s);
const char * t = [str cStringUsingEncoding:NSUTF8StringEncoding];
printf("%s\n",t);
}
return 0;
}
把char*转换成nsstring*
#import
int main(int argc, const char * argv[])
{
@autoreleasepool {
// insert code here...
const char * str = "你好";
NSString *s = [[NSString alloc]initWithCString:str encoding:
NSUTF8StringEncoding];
NSLog(@"%@",s);
NSString * t = [NSString stringWithUTF8String:str];
NSLog(@"%@",t);
}
return 0;
}