I have the following NSString:
NSString* searchURL = NSString stringWithFormat:@"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22%@%22)%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=",symbol; NSLog(@"URL IS: %@", searchURL);
Looks like the %22 is not being included when it is being printed:
URL IS: http://query.yahooapis.com/v1/public/yql?q=select220from2ahoo.finance.quotes2here `º≠ymbol [email protected]&format=json&env=http0X1.8CFB8P-1023-1.9907460.000000datatables.org-1.990746alltables.env&callback=
How can I make sure the %22 is included in my string?
If you want to include a “%” sign in a format string use “%%”
Just like in printf et al.
Read the full documentation of stringWithFormat to avoid other bad surprises …
% is a special character in format strings. Use
%% to escape literal percent signs.
% character are used in encoding space in the url formation.If you want to request any url you need to encoding that with stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding
. So the % sign that are appearing are the encoded form of space.So implement accordingly by clearing this fundamental