[英]URL decoding/encoding NSString
I am using three20's URL navigator and I want to create a map as follows:我正在使用three20的URL导航器,我想创建一个map如下:
[map from:[Group class] name:@"show" toURL:@"tt://group/(gid)/(name)"];
The issue here name can be multiple words and so there is spaces in between.这里的问题名称可以是多个单词,因此中间有空格。 Now I need to URL encode this
NSString
and decode it back.现在我需要 URL 编码这个
NSString
并将其解码回来。 How do I do this?我该怎么做呢? What is the easiest way to URL decode and encode
NSString
? URL 解码和编码
NSString
的最简单方法是什么?
- (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];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.