Vertical pipe symbol not found in NSURL

I am trying to place a search in the Google dictionary, but the url contains a vertical channel / bar | My code just doesn't 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]]; } 

using% 7C doesn't work either.

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

Consider the encoding of your URL using something like:

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

rather than manually doing it yourself. Maybe there are some characters in your mySearchString NSString that also need to be encoded. Run this encoding after you have stringWithFormat 'd full url together.

+19
source

All Articles