NSString 转 UNICODE char*:
NSString* value = @“value”;
cosnt char* str = [value cStringUsingEncoding:NSUnicodeStringEncoding];
NSString 转 utf8 char*
NSString* value= @“value”;
const char* str =[value UTF8String];
utf8 char* 转 NSString
NSString* value = [NSString stringWithCString:str encoding:NSUTF8StringEncoding];
char* 转 NSData
NSData* data = [NSData dataWithBytes:str length:strlen(str)];
NSString* value = [NSString initWithUTF8String:str];
NSData* data = [value dataUsingEncoding:NSUTF8StringEncoding];
NSData 转 char*
char* str = [data bytes];
NSData 转 NSString;
NSString* value = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSString 转 NSData
NSData* data = [@”vale” dataUsingEncoding:NSUTF8StringEncoding];
NSString 转 NSURL
NSString* url_value = [value stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL* url = [NSURL URLWithString:url_value];
NSURL 转 NSString
NSURL* url = [NSURL URLWithString:url_value];
NSString* value = [[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
- 本文固定链接: http://www.wy182000.com/2015/01/22/nsstring-nsdata-char-相互转换/
- 转载请注明: wy182000 于 Studio 发表