ios中URL字符串的URLencode与URLdecode

+(NSString*)encodeString:(NSString*)unencodedString{

// CharactersToBeEscaped = @":/?&=;+!@#$()~',*";

// CharactersToLeaveUnescaped = @"[].";

NSString*encodedString=(NSString*)

CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,

(CFStringRef)unencodedString,

NULL,

(CFStringRef)@"!*'();:@&=+$,/?%#[]",

kCFStringEncodingUTF8));

returnencodedString;

}

//URLDEcode

-(NSString*)decodeString:(NSString*)encodedString

{

//NSString *decodedString = [encodedString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding ];

NSString*decodedString=(__bridge_transferNSString*)CFURLCreateStringByReplacingPercentEscapesUsingEncoding(NULL,

(__bridgeCFStringRef)encodedString,

CFSTR(""),

CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding));

returndecodedString;

}

你可能感兴趣的:(ios中URL字符串的URLencode与URLdecode)