美文网首页
字符串转译

字符串转译

作者: 大漠赏花 | 来源:发表于2018-01-05 19:33 被阅读0次

    NSString *url = @"https://www.baidu.com/s?ie=UTF-8&wd=%E6%88%91%E7%9A%84%E5%89%8D%E5%8D%8A%E7%94%9F";

        CFStringRef encodedCFString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,

                                                                              (__bridgeCFStringRef) url,

                                                                              nil,

                                                                              CFSTR("?!@#$^&%*+,:;='\"`<>()[]{}/\\| "),

                                                                              kCFStringEncodingUTF8);

        NSString*encodedString1 = [[NSStringalloc]initWithString:(__bridge_transferNSString*) encodedCFString];

        NSString *charactersToEscape = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\| ";

        NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet];

        NSString *encodedUrl = [url stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];

        NSLog(@"\n%@\n%@\n%@",encodedUrl,encodedString1);

    参考资料:http://blog.csdn.net/lidongxuedecsdn/article/details/50497998

    相关文章

      网友评论

          本文标题:字符串转译

          本文链接:https://www.haomeiwen.com/subject/hugsnxtx.html