• Unicode解码、URL编码/解码


    + (NSString *) stringByReplaceUnicode:(NSString *)string
    {
        NSMutableString *convertedString = [string mutableCopy];
        [convertedString replaceOccurrencesOfString:@"\U" withString:@"\u" options:0 range:NSMakeRange(0, convertedString.length)];
        CFStringRef transform = CFSTR("Any-Hex/Java");
        CFStringTransform((__bridge CFMutableStringRef)convertedString, NULL, transform, YES);
        return convertedString;
    }
    -(NSString *)URLEncodedString
    {
        NSString *encodedString = (NSString *)
        CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                                  (CFStringRef)self,
                                                                  NULL,
                                                                  (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                  kCFStringEncodingUTF8));
        return encodedString;
    }
    -(NSString *)URLDecodedString
    {
        NSString *decodedString=(__bridge_transfer NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL, (__bridge CFStringRef)self, CFSTR(""), CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));
        return decodedString;
    }
  • 相关阅读:
    第12章 Swing编程
    第11章 AWT编程
    第10章 异常处理
    第9章 泛型
    Java 实例
    Spring 框架 (持续完善中)
    Java 程序员必备的5个框架 (持续完善中)
    IDEA 中建立Java项目步骤
    Java 实例
    Java 实例
  • 原文地址:https://www.cnblogs.com/hacjy/p/5142277.html
Copyright © 2020-2023  润新知