I am implementing a search using the following code snippet.
-(void)getData:(NSString *)searchString
{
//Search string is the string the user keys in as keywords for the search. In this case I am testing with the keywords "epic headline"
searchString = [searchString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *resourcePath = [NSString stringWithFormat:@"/sm/search?limit=100&term=%@&types[]=users&types[]=questions&types[]=topics",searchString];
[self sendRequests:resourcePath];
}
//URL sent to server as a result
send Request /sm/search?limit=100&term=epic headline&types[]=users&types[]=questions&types[]=topics
My search is not working as it is unable to handle the space between ‘epic’ and ‘headline’. How can I modify the search term so that the spacing can be handled?
Call stringByAddingPercentEscapesUsingEncoding on the result string to encode space characters as requiredby the rules of URLs.