another issue where I seem to have found a solution for ObjC but not MonoTouch.
I want to get NSUrl from a url (as a string).
A string can contain spaces and backslashes.
Why does NSUrl return null for such a string, even if these are valid URLs in the browser?
For example: NSUrl foo = NSUrl.FromString (@ " http://google.com/search ? \ Query");
foo == null
Any suggestions?
[NSURL URLWithString: [googlSearchString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
Link toStack Overflow ...
You probably need to process the string first with
stringByAddingPercentEscapesUsingEncoding:
... so that it can handle a valid URL.
URLWithString: Creates and returns an NSURL object initialized with the provided string.
NSString * urlString = @"http://example/newcase/path/fileNames"; urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding]; NSURL * url = [NSURL URLWithString:urlString]; NSLog(@"URL: %@", url);