I recently had a problem when comparing two NSURLs and compare one NSURL with an NSString(which is a URL address), the situation is I got an NSURLRequest from somewhere, I may or may not know the URL address it points to, and I have an URL NSString, say "http://m.google.com", now I need to check if the URL in that NSURLRequest is the same as the URL string I had:
[[request.URL.absoluteString lowercaseString] isEqualToString: [self.myAddress lowercaseString]];
this returns NO as the absoluteString
gives me "http://m.google.com/" whereas my string is "http://m.google.com" without a slash in the end, even if I create the NSURLRequest using
[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://m.google.com"]]
it still gives me "http://m.google.com/" for absoluteString
, I wonder is there any reliable way to compare to NSURL or one NSURL and one NSString?
check if one 'contains' another, but this is not reliable as 'http://m.google.com/blabla' contains 'http://m.google.com'.
convert the NSString to NSURL and use the
isEqual
method to compare two NSURL and hopefully NSURL's implementation ofisEqual
can figure it out?based on step 2, but convert each NSURL to a standard URL using
standardizedURL
?
Thanks a lot!
isEqualToString
method – ApplegateisEqual:
of theNSURL
does not "figure it out" :( – Washery