PDA

View Full Version : Foreign letters in NSURL




Ralle
Feb 9, 2009, 04:53 PM
I live in Denmark and here we have 3 additional letters (æ,ø,å) and I am making GET requests for XML content but NSURL fails whenever I put in any of the characters. They have to be escaped somehow but I am not sure how. This is where I call NSURL:
NSURL *xmlURL = [NSURL URLWithString:URL];



Aea
Feb 9, 2009, 05:14 PM
And how is URL defined?

Ralle
Feb 9, 2009, 05:33 PM
It is taken from a UISearchBar.

NSString* search = [searchBox text];
NSString* purl = @"http://www.google.com/search?query=";
NSString* url = [purl stringByAppendingString:search ];

xsmasher
Feb 10, 2009, 12:47 AM
Same way that you encode spaces and other special chars - stringByAddingPercentEscapesUsingEncoding

This code works for me:


NSString *url = @"http://www.google.com/search?q=æøå";
url = [url stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding ];
xmlURL = [NSURL URLWithString:url];