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: Satoshi Matsumoto <email@hidden>
- Date: Wed, 10 Mar 2004 16:50:56 +0900
Dear Louis,
Thank you for your kind information. It's very helpful.
But in following case, where absolute URLs are outside of base URL directory
baseURLString = @"
http://www.base.com/url/"
absoluteURLString = @"
http://www.base.com/img/image.jepg"
The result relativeURL should be @"../img/image.jepg"
I am going to write a method that can handle above cases...
Satoshi
on 04.3.10 4:24 PM, Louis C. Sacha at email@hidden wrote:
>
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.
_______________________________________________
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.