开发者

Way to build a querystring in obj-c that escapes as necessary?

开发者 https://www.devze.com 2023-02-25 16:47 出处:网络
I want to build a querystring in obj-c eg http://myurl.com/myservice?key=value&key2=value2 Just wondering how to go abo开发者_JAVA技巧ut doing this so that all the unfriendly characters (eg &

I want to build a querystring in obj-c eg http://myurl.com/myservice?key=value&key2=value2

Just wondering how to go abo开发者_JAVA技巧ut doing this so that all the unfriendly characters (eg &, %) get escaped properly?

Thanks


Will this work?

+(NSString*)urlEscape:(NSString *)unencodedString {
    NSString *s = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
        (CFStringRef)unencodedString,
        NULL,
        (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
        kCFStringEncodingUTF8);
    return [s autorelease]; // Due to the 'create rule' we own the above and must autorelease it
}
0

精彩评论

暂无评论...
验证码 换一张
取 消