1.常用方式
NSString *utf8Str = @"Testing";
NSString *unicodeStr = [NSString stringWithCString:[utf8Str UTF8String] encoding:NSUnicodeStringEncoding];
2.繁琐方式,但是更合适
NSString *utf8Str = @"Testing";
NSString * encodedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)utf8Str,NULL,(CFStringRef)@"!*'();:@&=+$,/?%#[]",
//The characters you want to replace go here
kCFStringEncodingUTF8 ));
网友评论