如何编码此URL以显示在UIWebview中:
http://de.wikipedia.org/?search=Bevölkerungsentwicklung
我试过了:
-stringByAddingPercentEscapesUsingEncoding:NSUnicodeStringEncoding
-stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding
和
CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)mobileUrl,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8);
谢谢
乔尔格
最佳答案
仅对URL字符串的搜索部分进行编码:
// searchString is the unescaped search string, e.g., "Bevölkerungsentwicklung"
NSString *encodedSearchString = [searchString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlString = [NSString stringWithFormat:@"http://de.wikipedia.org/?search=%@", encodedSearchString];
NSURL *url = [NSURL URLWithString:urlString];
(还要注意,NSUTF8StringEncoding是使用的编码。)
关于iphone - 带有特殊字符的NSURL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4145846/