在NSURL中未检测到垂直管道符号 [英] vertical pipe symbol not being detected in NSURL

查看:88
本文介绍了在NSURL中未检测到垂直管道符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Google字典中进行搜索,但网址中包含垂直的竖线/栏| 我的代码只是无法加载网站

I'm trying to place a search in google dictionary but the url contains a vertical pipe/bar | My code just fails to load the site

 //http://www.google.com/dictionary?aq=f&langpair=en|en&q=test+test+test&hl=en


if ([mySearchEngineName isEqualToString:@"Google Dictionary"]){
        NSLog(@"Currently searching %@ using %@", mySearchString, mySearchEngineName); 

        NSString *mutateSearchString = [mySearchString stringByReplacingOccurrencesOfString:@" " withString:@"+"];
        NSString *searchURL =[NSString stringWithFormat:@"http://www.google.com/dictionary?aq=f&langpair=en|en&q=%@&hl=en", mutateSearchString];
        NSURL *url = [NSURL URLWithString:searchURL];
        [webBrowser loadRequest:[NSURLRequest requestWithURL:url]];
    }

使用%7C也不起作用.

using %7C did not work either..

NSString *searchURL =[NSString stringWithFormat:@"http://www.google.com/dictionary?aq=f&langpair=en%7Cen&q=%@&hl=en", mutateSearchString];

推荐答案

请考虑使用以下方式对您的URL进行编码:

Consider encoding your URL using something like:

NSURL *url = [NSURL URLWithString:[searchURL stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]]; 

而不是自己手动进行.也许您的mySearchString NSString中有些字符也需要编码.一起 stringWithFormat 完整的URL后,运行此编码.

rather than manually doing it yourself. Perhaps there is some characters in your mySearchString NSString that also needs encoding. Run this encoding after you have stringWithFormat'd the full URL together.

这篇关于在NSURL中未检测到垂直管道符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆