How to compare URLs when one is in /Users/john format and other in file://localhost/Users/etc
I am enumerating through directories which returns URLs in the form:
file:/开发者_运维百科/localhost/Users/john/Documents/static.gif
I want to check these results against URLs in the form of:
/Users/john
Specifically, I want to know if the first URL is contained in the second.
I've been going through the various NSURL methods and can't find a method that will allow me to convert one form into the other for easy comparison, or actually do the comparison for me.
You can use the path
method to get the strings. The first URL will become @"/localhost/Users/john/Documents/static.gif"
and second remains the same.
You can check where second URL contains the first using,
if ( [[URL1 path] hasPrefix:[URL2 path]] ) {
NSLog(@"Contained");
}
精彩评论