Re: Conversion from an absolute URL to relative
Re: Conversion from an absolute URL to relative
- Subject: Re: Conversion from an absolute URL to relative
- From: "Louis C. Sacha" <email@hidden>
- Date: Tue, 9 Mar 2004 23:24:19 -0800
Hello...
It would probably be easiest to work with the urls as NSStrings,
using the NSURL methods that accept/return strings.
Then, you could do something like this:
NSString *baseURLString = @"
http://www.base.com/url/";
NSString *absoluteURLString =
@"
http://www.base.com/url/plus/other/stuff.html";
NSString *relativeURLString;
NSRange prefix = [absoluteURLString rangeOfString:baseURLString];
if (prefix.location == 0)
{
relativeURLString = [absoluteURLString
substringFromIndex:prefix.length];
}
else
{
/* base url was not found, or not at beginning of
absolute url */
relativeURLString = nil;
}
For the example URL strings above, the code should result in
relativeURLString containing the string @"plus/other/stuff.html",
which you could put back into an NSURL if you need to using it and
baseURLString.
Hope that helps,
Louis
Hi,
Are there any method in Cocoa to convert an absolute URL to a relative URL
with a given base URL?
Satoshi,
-----------------------------------------------------
Satoshi Matsumoto <email@hidden>
816-5 Odake, Odawara, Kanagawa, Japan 256-0802
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.