NSString / NSData / char* 类型之间的转换
- NSString 转化为 char *
1 | NSString * str= @“Test”; |
- char * 转化为 NSString
1 | NSString *str=[NSString stringWithCString encoding:NSUTF8StringEncoding]; |
- char * 转化 NSData
1 | 方法一: |
- NSData 转化 char *
1 | NSData data ; |
- NSData 转化 NSString;
1 | NSData* data; |
- NSString 转化 NSData
1 | NSData* xmlData = [@"testdata" dataUsingEncoding:NSUTF8StringEncoding]; |
- NSString 转化 NSURL
1 | //NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding ]]; |
- NSURL 转化 NSString
1 | NSURL *url=[NSURL URLWithString:urlString]; |