URL decoding/encoding NSString

后端 未结 2 845
情书的邮戳
情书的邮戳 2020-12-18 17:48

I am using three20\'s URL navigator and I want to create a map as follows:

[map from:[Group class] name:@\"show\" toURL:@\"tt://group/(gid)/(name)\"];


        
相关标签:
2条回答
  • 2020-12-18 18:26
    - (NSString *)encodedURLString {
        NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)self,
                                                                               NULL,                   
                                                                               CFSTR("?=&+"),          
                                                                               kCFStringEncodingUTF8); // encoding
        return [result autorelease];
    }
    
    - (NSString *)encodedURLParameterString {
        NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                                               (CFStringRef)self,
                                                                               NULL,
                                                                               CFSTR(":/=,!$&'()*+;[]@#?"),
                                                                               kCFStringEncodingUTF8);
        return [result autorelease];
    }
    
    0 讨论(0)
  • 2020-12-18 18:34

    You can start with

    NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
    

    to get the url from the NSString.

    Also, see here about URLencoding it with the proper escapes.

    0 讨论(0)
提交回复
热议问题