iOS文字列UTF 8符号化復号、複数回符号化復号

2106 ワード

	// (& %26) (= %3D) (/ %2F) (, %2C)
        //  
        NSString *originalStr = @"Hello &=/,. ,、。";
        NSString *encodeStr_00 = [originalStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; //  ( )
        NSString *encodeStr_01 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)originalStr, NULL, (CFStringRef)@"!*'();: @&=+ $,./?%#[]", kCFStringEncodingUTF8)); //  、 、 
        //  
        NSString *decodeStr_00 = [encodeStr_00 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSString *decodeStr_01 = [encodeStr_01 stringByRemovingPercentEncoding];
        //  
        NSString *originInitStr = @"type=1&code=1";
        NSString *encodeInitStr_1 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)originInitStr, NULL, (CFStringRef)@"!*'();: @&=+ $,./?%#[]", kCFStringEncodingUTF8));
        NSString *encodeInitStr_2 = [NSString stringWithFormat:@"level=2,%@", encodeInitStr_1];
        NSString *encodeInitStr_3 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)encodeInitStr_2, NULL, (CFStringRef)@"!*'();: @&=+ $,./?%#[]", kCFStringEncodingUTF8));
        NSString *encodeInitStr_4 = [NSString stringWithFormat:@"range=3,%@", encodeInitStr_3];
        NSString *encodeInitStr_5 = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)encodeInitStr_4, NULL, (CFStringRef)@"!*'();: @&=+ $,./?%#[]", kCFStringEncodingUTF8));
        //  
        NSString *decodeInitStr_3 = [encodeInitStr_5 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSString *decodeInitStr_2 = [decodeInitStr_3 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSString *decodeInitStr_1 = [decodeInitStr_2 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];