objective c - NSString and NSUrl not converting properly -
So I'm trying to retrieve data from an XML stream coming from a URL. This URL is configured on a search string that is user input. Is there any reason why this code should not work?
NSString * searchString = "Geoff"; NSString * updatedURL = [NSString stringWithFormat: @ "http://mysearchpage.com/searchQuery=%@", search-string]; NSLog (updatedURL); NS URL * URL = [[NSURLLock] InitvastString: Update URL];
Now this single word works well for searches, but as soon as I try and search for the first and last name, the url returns zero every time whether it is the string Is there any behavior with which can be caused?
I also tried to replace "" with "% 20" when the search string was added to see if this was a problem. I did this:
NSURL * url = [[NSURL alloc] initWithString: [updatedURL stringByReplacingOccurrencesOfString: @ "" withString: @ "%% 20"]];
Any ideas? thank you in advanced!
You should use the -stringByAddingPercentEscapesUsingEncoding:
method of NSString:
NSURL * url = [[NS URL light] initWithString: [updatedURL stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
Comments
Post a Comment